1. First as root install GO
    1.1. Goto /usr/local
    1.2 Make go folder and cd to it
    1.3 Issue the wget command depending of the CPU you have

$ wget -c https://golang.org/dl/go1.15.2.linux-amd64.tar.gz [64-bit]
$ wget -c https://golang.org/dl/go1.15.2.linux-386.tar.gz [32-bit]

1.4 extract the tar archive files into /usr/local directory using the command sudo tar -C /usr/local -xvzf go1.15.2.linux-amd64.tar.gz

Configuring GoLang Environment in Linux

2. First, set up your Go workspace by creating a directory ~/go_projects which is the root of your workspace. The workspace is made of three directories namely:

  1. bin which will contain Go executable binaries.
  2. src which will store your source files and
  3. pkg which will store package objects.

Therefore create the above directory tree as follows:

$ mkdir -p ~/go_projects/{bin,src,pkg}
$ cd ~/go_projects
$ ls

3. Now it’s time to execute Go like the rest of Linux programs without specifying its absolute path, its installation directory must be stored as one of the values of $PATH environment variable.

Now, add /usr/local/go/bin to the PATH environment variable by inserting the line below in your /etc/profile file for a system-wide installation or $HOME/.profile or $HOME./bash_profile for user-specific installation:

Using your preferred editor, open the appropriate user profile file as per your distribution and add the line below, save the file, and exit:

export  PATH=$PATH:/usr/local/go/bin

4. Then, set the values of GOPATH and GOBIN Go environment variables in your user profile file (~/.profile or ~/bash_profile) to point to your workspace directory.

export GOPATH="$HOME/go_projects"
export GOBIN="$GOPATH/bin"

Note: If you installed GoLang in a custom directory other than the default (/usr/local/), you must specify that directory as the value of the GOROOT variable.

For instance, if you have installed GoLang in the home directory, add the lines below to your $HOME/.profile or $HOME/.bash_profile file.

export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin

5. The final step under this section is to effect the changes made to the user profile in the current bash session like so:

$ source ~/.bash_profile
OR
$ source ~/.profile

Verify GoLang Installation

6. Run the commands below to view your Go version and environment:

$ go version
$ go env