Go, or Golang is an open-source language developed by Google to create simple, reliable, and efficient software. This tutorial explains how to install Golang on a Vultr Ubuntu cloud server instance.
This guide is tested on a new Vultr Ubuntu 20.04 LTS cloud server instance, and works on any version of Ubuntu. Follow our best practice guides before installing Golang.
Because the Golang package is not always up to date in the Ubuntu repository, it's preferred to download the official website's latest version.
Change to a temporary directory for the installation.
$ cd /tmp
Select the latest package for your architecture from https://golang.org/dl/ and download it.
$ wget https://golang.org/dl/go1.<VERSION_NUMBER>.linux-amd64.tar.gz
Extract the Golang executable to /usr/local
.
$ sudo tar -C /usr/local -xzf go1.<VERSION_NUMBER>.linux-amd64.tar.gz
To use Golang, set the required environment variables in your .profile
.
$ echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.profile
$ echo "export GOPATH=~/.go" >> ~/.profile
Reload your profile to begin using Golang.
$ source ~/.profile
Verify you installed the expected version of Golang.
$ go version
# go version go1.<VERSION_NUMBER> linux/amd64
Create a Hello World program to test your environment.
$ nano helloworld.go
Paste the following in helloworld.go
.
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello world!")
}
Save the file and exit the Nano editor.
Run the program.
$ go run helloworld.go
# Hello world!
You have installed Golang. See more information at golang.org.