
Go, or golang is a modern open source programming language developed by Google. Many popular applications such as Kubernetes, Terraform, Rancher, Docker, etc. are written in Go language. This guide explains how to install Go on Ubuntu 20.04 Focal Fossa.
Install Go on Ubuntu 20.04
Perform the following steps to install Go on Ubuntu 20.04:
Step 1 – Download Go
Go 1.14.2 is the latest version available currently. It’s recommended to check latest version at official download page if any available. Run the below command as root or sudo user to download Go binary archive using wget:
wget -c https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local
Step 2 – Set Go Path Variable
Now we will set location of the Go directory to the $PATH
environment variable. So it will help system to know where to find the Go executable binaries.
Edit the /etc/profile
file for global installation or $HOME/.profile
file for a current user installation:
export PATH=$PATH:/usr/local/go/bin
Save and close the file.
Next, load the new PATH environment variable into the current shell session:
source ~/.profile
Step 3 – Verify Installation
Verify the Go installation using Go version command:
go version
Output should look like this:
go version go1.14.2 linux/amd64
Step 4 – Create Test Program
To test GO is properly installed, you can create a simple program which will print “Welcome to GO” message. Follow below steps to build simple program.
First of all, create a workspace directory for Go. You can get more details about go workspace directory visit this page:
mkdir ~/go
Next, create a directory src/welcome
inside it using below command:
mkdir -p ~/go/src/welcome
In this directory create a file named welcome.go
and add below content to it:
sudo nano ~/go/src/welcome/welcome.go
package main
import "fmt"
func main() {
fmt.Printf("Welcome to GO\n")
}
Now go back /go/src/welcome
to build the file and issue go build
command:
cd ~/go/src/welcome
go build
The above command will build an executable file with name welcome
.
You can run the program using executable using following command:
./welcome
Welcome to GO
Conclusion
You successfully learn how to install GO on Ubuntu 20.04 Focal Fossa system.
If you have any queries or suggestion, feel free to comment below.
Leave a Reply