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 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 so command will be as follow:
    curl -O
  • 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
  • Wait a moment until it download the code completely, then execute the following command: