Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

How To Build and Install Go Program?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Go (also known as Golang) is an open-source programming language focused on simplicity, reliability, and efficiency, developed at Google in 2007. It’s a multipurpose, statically typed, compiled programming language. It’s used for server-side (backend) programming, game development, cloud-native applications, and even Data Science. It is also popular for making command-line tools and is easy to learn. In Go translating source code into a binary executable is called building. go build built the package along with its dependencies into a binary executable, whereas go install first build then install the binary to your $GOPATH/bin folder. In other words, it installs the program into the system so that you can access it whenever or from wherever you need it.

Build and Install Go Program

Let’s see an example, follow the below steps to build and install the go program,

Step 1:  Create a program main.go and initialize the go.mod  file

go mod init gfg


package main
import "fmt"
// Main function
func main() {
    fmt.Println("Welcome to GeeksforGeeks!")
    fmt.Println("Thanks for visiting us!")

Step 2: Build the program

go build

As you can see that in your directory there is a binary executable as per your OS.



Run the executable, On Unix systems


On windows,



building the program

Now we’ve created a single executable binary that contains, not only your program but also all of the system code needed to run that binary.

Step 3: Install the program

go install


Installing the program

as you can see, the binary executable has been moved to the $GOPATH/bin directory. To check that executable, run the following commands,

go env GOPATH

ls $GOPATH/bin | grep gfg

Step 4: Verify the installation

Change the directory wherever you want and run that executable:





Now you can take the programs you write and install them into your system, allowing you to use them wherever, whenever you need them.

My Personal Notes arrow_drop_up
Last Updated : 02 Jun, 2022
Like Article
Save Article
Similar Reads