Go, often called golang, is a modern open source programming language created by Google that allows you to build real-time and efficient applications.
Many popular applications, such as Kubernetes, Docker, Prometheus and Terraform, are written in Go.
This tutorial explains how to download and install Go on Ubuntu 20.04.
Complete the following steps to install Go on Ubuntu 20.04
At the time of writing this article, the latest version of Go is 1.14.2. When we download the installation package, please browse Go official download page, and check if there is a new version available.
Run the following command as root or another sudo user to download and unzip the Go binary file to the /usr/local
directory:
wget -c https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz -O -| sudo tar -xz -C /usr/local
By adding the Go directory to the $PATH
environment variable, the system will know where to find the Go executable.
This can be done by adding the following line to the /etc/profile
file (installed system-wide) or $HOME/.profile
file (installed by the current user):
export PATH=$PATH:/usr/local/go/bin
Save the file and reload the new PATH environment variable into the current shell session:
source ~/.profile
Verify the installation process by printing the Go version number.
go version
The output should look like this:
go version go1.14.2 linux/amd64
To test the Go installation process, we will create a workspace and build a simple program to print the classic "Hello World" message.
GOPATH
variable, specified as the location of the workspace, is set to $HOME/go
. To create a workspace directory, enter:mkdir ~/go
src/hello
:mkdir -p ~/go/src/hello
In that directory, create a new file with the name hello.go
:
package main
import"fmt"
func main(){
fmt.Printf("Hello, World\n")}
To learn more about the Go workspace directory, browse Go Documentation Page.
~/go/src/hello
directory, and run go build
to build the program:cd ~/go/src/hello
go build
The above command will build an executable file called hello
.
. /hello
The output should look like this:
Hello, World
Now that you have downloaded and installed Go on your Ubuntu system, you can start developing your Go project.
Recommended Posts