In this article, we would discuss how to install Go programming language in Ubuntu 20.04 LTS release. The programming language Go first released on November 10, 2009. And, at the time of writing the article, the latest stable release is v1.14.5.
There are two methods which we would discuss to install the Go programming language –
- through binary release available on official website of Go, or
- standard Ubuntu repository.
We would like to clarify, at the time of writing only v1.13.8 can be installed through standard Ubuntu repository.
Note: Following operations may require you to have superuser privileges. In case you don’t have one, then contact your System Administrator for assistance.
Install Go in Ubuntu 20.04 LTS release
Method I. through binary release available on official website of Go programming language.
Visit Golang’s official website; on the Homepage –> click on Button – Download. It would take you to the download page wherein, download for Linux – go1.14.5.linux-amd64.tar.gz
The file size of approximately 118 MBs would get downloaded. Thereafter, we use tar command-line utility to extract the compressed file. Hence, issue the following in terminal –
cd /path/to/package/ tar -xvf go1.14.5.linux-amd64.tar.gz
It would create a directory go. Now, to set system-wide environment variables – edit ~/.bashrc
file –
nano ~/.bashrc
We have used nano text editor. You can choose any. Next, append the file with following entries –
export PATH="/path/to/directory/go/bin/:$PATH"
where, replace /path/to/directory/ with relevant PATH to directory Go.
Lastly, open a new terminal and issue the following to verify the installation –
go version
It should return the following –
go version go1.14.5 linux/amd64
Method II. through standard Ubuntu repository. As already discussed, at the time of writing the latest stable release available through this process was – v1.13.8. We need to update the repository first to make the latest version of the package available –
sudo apt update
Then, to install Go programming language –
sudo apt install golang-go
Lastly, to verify the Go version installed –
go version
It should return with –
go version go1.13.8 linux/amd64
In conclusion, we have discussed how to install Go programming language in Ubuntu 20.04 LTS release.
Additional Info –
In this section, we would discuss how to run our first Go code/program in brief. Open a text editor and append the file with following code –
package main import "fmt" func main() { fmt.Printf("Hello!\n") }
And, save the file as hello.go
Next, create a binary executable using go build
command –
go build hello.go
It would create a binary executable hello in current directory. To execute it –
./hello
It should return –
Hello!