Installing Golang : The fast way

Steps only for Ubuntu. Other OS quick installation guide coming up soon!

So, this article is useful when you are in hurry and obviously, want to trust me :)


There are basically two ways to install golang - one is using the classical apt-get method and the other one is installing from source. he


First method

    $ sudo apt-get update
    $ sudo apt-get install golang

This will pretty much do the thing. Just two commands.
You can verify the installation just by checking this:
    $ go env GOROOT

This command will output the directory name where go is installed. Usually, it will show /usr/lib/go.

You can check go version:
    $ go version
    go version go1.5.1 linux/amd64

You are set to use golang. Please don't forget to configure $GOPATH and $GOBIN directories explained below. 

Note: This method will install go version which is included in os package. If you need to install particular version of go, read on.

Second Method

You can install go directly from source. Also, golang is a beautiful language. It is getting widely accepted and evolving periodically. So, you can install whatever version you want to.

Pre-requisites: Git should be preinstalled in your system to use this method as we will be cloning a git repo directly.

Following commands will create a directory named which will be go installation directory. You can run them anywhere. To make it easy for you, do it in home directory ;-)
    $ git clone https://go.googlesource.com/go
    $ cd go
    $ git checkout go1.7
    $ cd src
    $ ./all.bash

If everything is fine, you  should see the below output:
ALL TEST PASSED

Most important step, set your GOPATH and GOBIN path variables

Now, to utilize go development at its fullest, go programs are generally written in a directory which will all the go related packages, dependencies.

In short, you just create a directory and consider it as your workspace for go programs. A directory, anywhere. Later this directory will hold three sub directories - src, pkg, bin. 
src - will contain all the source code.
pkg - will contain all the packages which your source code will use.
bin - will contain the binary files.

But the go compiler should know where this directory is. So, just follow this
    $ mkdir gocode
    $ cd gocode
    $ mkdir src pkg bin

Set the paths
    $ export GOPATH=$HOME/gocode
    $ export GOBIN=$GOPATH/bin

Provided your gocode directory is in home directory. Now to avoid exporting the path each time you login, you need to put these commands in bashrc or similar file.

    $ vim ~/.bashrc
    * Append the two export commands in this file and save.

Comments

Popular posts from this blog

error: stray '\' in program

error: invalid application of ‘sizeof’ to incomplete type ‘struct ’

ssh: Could not resolve hostname git: No address associated with hostname