updated: 4th of September 2012
published: 22nd of August 2019
This will just be a quick post on how to install Golang on Ubuntu 1804. There will be no earth shattering knowledge bombs, it's more of a documentation post for myself. Others may or may not find it useful.
Download the Golang package for your system and architecture.
curl -OL https://dl.google.com/go/go1.15.1.linux-amd64.tar.gz
Once downloaded, extract the tar file to install Golang.
sudo tar -C /usr/local -xzf go1.15.1.linux-amd64.tar.gz
This will create a binary here: /usr/local/go/bin/go
In order to effectively utilise go you will need to setup a couple of environment variables. The first one adds the the go binary to your $PATH
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.zshrc
The next one defines the root directory for your $GOPATH . Your $GOPATH is the location of your Go workspace. All of your go projects will get built under this workspace.
echo 'export GOPATH=$HOME/go' >> ~/.zshrc
Finally source your rc file to load the variables into your environment and create the $GOPATH workspace directory.
source ~/.zshrc
mkdir $GOPATH
Confirm that Go is installed correctly.
go version
# output
go version go1.12.9 linux/amd64
Create a project directory under your $GOPATH workspace.
cd $GOPATH
mkdir hello && cd hello
Create a hello.go file.
// hello.go
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
Compile the project into a binary.
go build
A binary hello will be created, execute the binary and bask in your glory.
./hello
# output
hello, world
That's it. Go installed, configured and ready to be stretched to its limits.