How to set up Go on Ubuntu
Go is an open source programming language which was designed by Google to improve programming productivity. It provides an easy way to build simple, reliable, and efficient software.
If you are trying to develop in Go, as the first step, you need to setup your computer for working with GO. I think this simple blog post will help you for that.
Step 1: Install Go on Ubuntu.
Get latest security updates and apply these updates to your Ubuntu system.
$ sudo apt-get update
$ sudo apt-get -y upgrade
Next, we need to download Go language binary archive file.
$ wget https://dl.google.com/go/go1.13.3.linux-amd64.tar.gz
You can download latest version or 32 bit version from official download page.
Now we need to extract the downloaded archive and install it to a desired location on the system.
$ sudo tar -xvf go1.13.3.linux-amd64.tar.gz
$ sudo mv go /usr/local
I am installing it under /usr/local directory . You also can put this under any location.
Step 2: Setup Go Environment
As the second step, we need to setup Go language variables for our project. There are 3 environmental variables to setup. GOROOT, GOPATH, PATH are those 3 variables.
Let’s see how these variables are setup.
GOROOT is the location where Go package is installed on your system.
GOPATH is the location of work directory. In my case, my project directory is ~/Test/Test1. It will differ according to your project location.
PATH variable is set to access Go binary system wide.
$ export GOROOT=/usr/local/go
$ export GOPATH=$HOME/Test/Test1
$ export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
This environment will be set for our current session only. If we need to make it permanent we should add above commands in /etc/profile file. First open the /etc/profile.
$ sudo gedit /etc/profile
Then add following configurations.
export GOROOT=/usr/local/go
export GOPATH=$HOME/Test/Test1
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
If you are done in this way, you need to restart the computer to apply changes.
Now it is time to check whether we have successfully installed and configured Go language on our system. For that use the following command to check the Go version.
$ go version
If you have done correctly, the version will displayed from the above command.
Reference: