How to install go language and set environment variables properly?

SAUMYA RANJAN SAHOO
2 min readMay 11, 2019

--

Go is a simple programming language which is statically typed. It is an efficient and reliable language and easy to learn and build enterprise applications.

In this article, we will learn how to install the golang (Go language alternatively called golang) and set the environment variables properly.

Let’s start a step by step guide to install golang.

step-1

Download the golang binaries from the official golang website: https://golang.org/doc/install

Download the compressed binaries for your appropriate OS.

step-2

After successful completion of the download, go to your download directory and open terminal.

enter the below command:

sudo tar -C /usr/local -xzf go1.12.1.linux-amd64.tar.gz

Note: You can set your compressed file version name here

All the binaries are extracted to your /home/usr/local directory.

You can verify the files in the /home/usr/local directory by using the commandcd /home/usr/local

step-3

Set the environment variables to your shell path.

To set the environment permanently save the path in /.profile file or /.bashrc file.

sudo nano $HOME/.profile 

save the below line at end of the file.

export PATH=$PATH:/usr/local/go/bin
export GOPATH=/home/saumya/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN

then source the file to set all the path into the current shell.

enter ctrl+x then y then enter to save the file.

step-4

source $HOME/.profile

Now all the path are set temporarily in the current shell. To set permanently logout and login the current user.

Now the golang is successfully installed you can check by entering the command go version and you can find the installed version of golang.

Now you have successfully installed golang in your machine.

--

--