Installing Go
- Update and upgrade the Ubuntu package by running the following two commands:
sudo apt-get update sudo apt-get -y upgrade - Get the url address to download stable package of Go by visit https://golang.org/dl/ then copy the link address.
- Download Go package by running the following command. Assume that the url address that is fetched from previous step is
https://dl.google.com/go/go1.11.4.linux-amd64.tar.gzso command will be as follow:curl -O https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz - Unpack the package using the following command:
tar -xvf go1.11.4.linux-amd64.tar.gz - Move the unpacked Go package to
/usr/localsudo mv go /usr/local
Setting up GOPATH
- Open
.profilefile as follow:sudo nano ~/.profile - Add the following lines at the end of file:
export GOPATH=$HOME/goprojects export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin - Refresh the profile by running following command:
source ~/.profile - Create the workspace folder as follow:
mkdir $HOME/goprojects
Testing Go Installation
- Type the following command to find out the Go version. It should show the version of installed Go.
go version - Download
HelloWorldcode by running the following command:go get github.com/golang/example/hello - Wait a moment until it download the code completely, then execute the following command:
$GOPATH/bin/hello