Go is an open-source programming language developed by a team at Google. It provides easy to build simple, reliable, and efficient software. This language is designed for writing servers, that’s why it is using widely these days. Go has released the latest version 1.20.

Advertisement

This tutorial will help you to install Go 1.20 on your Ubuntu 19.10, 18.04 LTS, 16.04 LTS, and 14.04 LTS systems.

Step 1 – Install Go on Ubuntu

Login to your Ubuntu system using ssh and upgrade to apply latest security updates there.

sudo apt-get update  
sudo apt-get -y upgrade  

Now download the Go language binary archive file using following link. To find and download latest version available or 32 bit version go to official download page.

wget https://dl.google.com/go/go1.20.5.linux-amd64.tar.gz 

Now extract the downloaded archive and install it to the desired location on the system. For this tutorial, I am installing it under /usr/local directory. You can also put this under the home directory (for shared hosting) or other location.

sudo tar -xvf go1.20.5.linux-amd64.tar.gz   
sudo mv go /usr/local  

Step 2 – Setup Go Environment

Now you need to setup Go language environment variables for your project. Commonly you need to set 3 environment variables as GOROOT, GOPATH and PATH.

  • GOROOT is the location where Go package is installed on your system.
    export GOROOT=/usr/local/go 
    
  • GOPATH is the location of your work directory. For example my project directory is ~/Projects/Proj1 .
    export GOPATH=$HOME/Projects/Proj1 
    
  • Now set the PATH variable to access go binary system wide.
    export PATH=$GOPATH/bin:$GOROOT/bin:$PATH 
    

All the above environment will be set for your current session only. To make it permanent add above commands in ~/.profile file.

Step 3 – Verify Installation

At this step, you have successfully installed and configured go language on your system. First, use the following command to check the Go version.

go version 

go version go1.20.5 linux/amd64

Now also verify all configured environment variables using following command.

go env 

GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/Projects/Proj1"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
...
...

Conclusion

In this tutorial, you have learned to install latest Golang on Ubuntu 18.04 and 16.04 Linux systems.

Share.

43 Comments

  1. Finally an article that works! Nice work man. After hours of wrestling with this trying to get “go install” to work you helped me a bunch!

  2. Karen Avetyan on

    There is a Snap package available for Go. https://snapcraft.io/go
    It can be installed on Ubuntu systems with the following command:

    sudo snap install go –classic

    P.S. When installing snap there is no need to add PATH variables.

  3. Awful ! I tried migrating from Go 10 to Go 11 using ur approach. I had many projects in ~/go folder and it was merged with go 11 contents and I realized what was happening when my move failed. Lucky me!! but things got too messy to separate new files. You should have had a caution or something to rename existing ~/go folder to something.

  4. Hello Sir,

    Tecadmin really very helpful for me.

    I am follow all your tutorials and topics.Now i want one suggestion for new topic is: for webRTC ( turnserver, go, and collider) installation on ubuntu 17.10.

    If you can it’s very very for me.

    In advance Thank you

  5. Amazing, thanks. Only one point would be that official repository go-golang package puts executables to /usr/bin so maybe would be better to keep it consistent for people that switch from outdated version?

  6. Felipe Ortiz de Almeida on

    For ensuring that all works, I have added the environment variables in “~/.bashrc”, “~/.profile” and ” /etc/profile” too. Well, it’s working. Thank you!

  7. IT is not working after this
    All above environment will be set for your current session only. To make it permanent add above commands in ~/.profile file.

  8. Thank you for a wonderful tutorial .I am lost for the steps when it said “All above environment will be set for your current session only. To make it permanent add above commands in ~/.profile file. ”

    I am quite new to this and need a stepwise instructions just like you have given in installing golang. Kindly help. THANK YOU !!!!

  9. Adem Kerenci on

    In my case, I am using Ubuntu 16.04.02 LTS, putting the GOROOT, GOPATH and PATH environmental variables to .profile does not work, I just try to put to .bashrc and it works. Btw, thanks for easy workaround for go.

    • Elliott Beach on

      Why explicitly state the target filename? The published version will work if required directories exist as expected.

  10. GOPATH is the location of your work directory. For example my project directory is ~/Projects/Proj1 .
    $ export GOROOT=$HOME/Projects/Proj1

    Correct value is:
    $ export GOPATH=$HOME/Projects/Proj1

Exit mobile version