Site icon DesignLinux

How to Install Go on Ubuntu 22.04

how-to-install-go-on-ubuntu-22-04

Go, or golang is a cross-platform and open source programming language developed by Google Engineers. Many popular applications such as Kubernetes, Terraform, Rancher, Docker, etc. are written in Go language. This article explains how to install Go on Ubuntu 22.04 Jammy Jellyfish.

How install Go on Ubuntu 22.04

Perform the following steps to install Go on Ubuntu 22.04:

Step 1 – Download Go

The latest version of Go language is 1.19.3. It’s advisable to check latest version at official download page if any available. You should run the below command as root or sudo user to download Go binary archive using wget:

wget -c https://dl.google.com/go/go1.19.3.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local

Step 2 – Set Go Path Variable

After that 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.

Now, 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

To check the installation use the below command:

go version

It should show output as following:

go version go1.19.3 linux/amd64

Step 4 – Create Test Program

We will create a simple program to check GO installed properly, which will print “Welcome to GO” message. Perform following 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 22.04 Jammy Jellyfish system.

If you have any queries or suggestion, feel free to comment below.

Exit mobile version