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.gz
so 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/local
sudo mv go /usr/local
Setting up GOPATH
- Open
.profile
file 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
HelloWorld
code 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