Linux Mint

How to Install Go on Linux Mint 20?

Go is an open-source and modern programming language that is used to build efficient and reliable software. Since it is a compiled language, therefore, we can easily compile it on any platform and create an executable file.

Go can be installed on Linux Mint 20 from the base repository and the Go tarball.

Installing Go on Linux Mint 20 from the Standard Repositories

Go is open-source, therefore, it is the part of Linux Mint 20 base repository and we can install it from there.

Open the terminal and update the apt package listing:

$ sudo apt update

Now, install Go with the command:

$ sudo apt install golang

Once Go is installed, check the installed version using the command below:

$ go version

As of writing, the latest version of Go is 1.16. Since the base repositories do not always include the most current version of the application, therefore an older version of Go is installed on my Linux Mint.

Installing Go on Linux Mint 20 from the Official Tarball

Complete the below-given steps to install Go on Linux Mint 20 from the official tarball:

Step 1: Download Go official tarball
First, fire up the terminal and download the Go latest official tarball:

$ sudo wget https://golang.org/dl/go1.16.linux-amd64.tar.gz

Step 2: Extract Go tarball
Then, extract the Go archive file in the /usr/local directory with the command below:

$ sudo tar -C /usr/local -xzf go1.16.linux-amd64.tar.gz

Step 3: Set the path variable
Next, we have to set the path environment variable value in the .bashrc file. Open the .bashrc file in the text editor:

$ nano ~/.bashrc

Add the below-given line in the .bashrc file, so that the system can find the Go binary files:

export PATH=$PATH:/usr/local/go/bin

Step 4: Verify the Go installation
Once the path variable is set, open the new terminal window and verify the Go installation with the command:

$ go version

In the output, you can see that the latest version of Go is installed on my Linux Mint 20 system.

Getting Started with Go on Linux Mint 20

Let’s create a Go file and run the first Go program:

package main
import "fmt"
func main() {
    fmt.Println("Hello from the LinuxHint")
}

Run your .go file with the command:

$ go run <file_name>
$ go run hello.go

Conclusion

We can install Go on Linux Mint 20 from the base repository and the Go tarball. This post focuses on Go installation on Linux Mint 20. Moreover, we have also created and executed our first Go program.

About the author

Kamran Sattar Awaisi

I am a software engineer and a research scholar. I like to write article and make tutorial on various IT topics including Python, Cloud Computing, Fog Computing and Deep Learning. I love to use Linux based operating systems.