Monday, March 26, 2018

How To Install Golang

Hi All,

In this post, I will teach you how to install Golang on your PC, currently, I'm working on Ubuntu OS  I will show you how to install Golang on Ubuntu OS first.

Go to the following link,

https://golang.org/dl/

Then download Golang according to your OS I'm on Ubuntu so I'm going to download Linux one from here,



After your download is finished you have to go to where your download file is placed and then extract it into /usr/local creating Go tree /usr/local/go. Use the following command as sudo.  

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


Now we have to set /usr/local/go/bin to the PATH environment variable. Use the following command to open bashrc via Vim text editor or use any text editor. 

sudo vim ~/.bashrc

Then add the following line to bottom of the file,

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


Let's create a workplace for Go and test our installation is working or not by using a sample code.

Go to your home by using the following command,

cd /home/username/

Then create directory call workplace using the following command,  

mkdir workplace

Then go inside that created directory and create directory call go,

mkdir go

Then go inside that created directory and create directory call src,

mkdir src

We will use GitHub for later in our projects so let's create github.com directory inside the src directory,

mkdir github.com

Then inside the github.com directory make a directory with your Github username.

mkdir yourusername


Following is my workspace path,

workspace/go/src/github.com/nisalsp9/


Let's create our first project directory, go inside your GitHub username directory and make the following directory,

mkdir hello    


Before we start our test project we have to set GOPATH to our workspace, open bashrc add following lines to the bottom of the file.

export GOPATH="/home/nisalsp9/workspace/go"
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
export GOROOT=/usr/local/go

After you add above line you have to source the bashrc file use following command to do that,

source ~/.bashrc 


We will create a hello world program in our next post and test our installation is working, bye ..!

Following are references to Golang installation in different OSs,





No comments:

Post a Comment