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.
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.
43 Comments
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!
thanks man!
You forgot to say sudo ln -s /usr/local/go/bin/go /usr/bin/go
It helps me a lot, Thanks!
update-golang is a script to easily fetch and install new Golang releases:
git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh
nice work, thanks a lot
That was helpful, thanks man.
Or just go to https://github.com/golang/go/wiki/Ubuntu
Best tech support site ever.
nice work!
I need such short tutorial, Thanks Rahul
Thank you sir
Thanks bhai
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.
Thanks! I finally found this when I couldn’t get apt-get xxx working. This works great.
where will i get ~/.profile file?
yo, nice work Rahul !!!
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.
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
Thanks Rahul
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?
Thank you
thanks rahul
For ensuring that all works, I have added the environment variables in “~/.bashrc”, “~/.profile” and ” /etc/profile” too. Well, it’s working. Thank you!
Good work
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.
how to remove golang make a page of that to
Thank you Rahul for the comprehensive guide!
Thanks dude !!
Thanks! Painless and easy
Thanks
Thank you Rahul for this tutorial, very helpful
ty
Gracias, al fin instale go1.9 🙂
Thanks
Thanks
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 !!!!
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.
Great, straightforward tutorial. Thanks!
Also,
$ sudo mv go /usr/local
Shoould read
$ sudo mv go /usr/local/go
Why explicitly state the target filename? The published version will work if required directories exist as expected.
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
Thanks Roman,
I have updated tutorial.