Getting started with Go with the GVM and some other important tools

Yeah.. I have to switch to GO AKA Golang to write a little app for solving a scalability issue. Go has some advantages such as very quickly compile, concurrency, garbage collector and functions as first class object. Whatever, today I am writing not to introduce the language rather installing the latest stable version without any error as well as some other important supporting tools to get started with GO.

I installed it by the GVM (Go Version Manager). By the GVM, you can install multiple versions and switch among them. Okay. First, let’s install the GVM, type the following command

bash <<(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

It will ask for run another command like following:

source ~/.gvm/scripts/gvm

Basically, it will download, install and append GVM directory to your bash profile. In case it doesn’t append, then you will have to do it by manually.

For the Linux based OS, open ~/.bashrc orfor the OSX based OS open ~/.bash_profile. And, then append the following line:

[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"

Then, make it effective, run the following command

source ~/.bashrc   ##For Linus
source ~/.bash_profile  ##For OSX

In order to check GVM is properly installed or not. Type following command:

gvm version

If it’s installed, then it would show:

Go Version Manager v1.0.22 installed at /home_directory/.gvm

Now, type the following command to see the list of versions to be installed,

gvm listall

Available versions

gvm gos (available)
 
   go1
   go1.0.1
   go1.0.2
   go1.0.3
   go1.1
   go1.1.1
   go1.1.2
   go1.1rc2
   go1.1rc3
   go1.2
   go1.2.1
   go1.2.2
   go1.2rc2
   go1.2rc3
   go1.2rc4
   go1.2rc5
   go1.3
   go1.3.1
   go1.3.2
   go1.3.3
   go1.3beta1
   go1.3beta2
   go1.3rc1
   go1.3rc2
   go1.4
   go1.4.1
   go1.4.2
   go1.4.3
   go1.4beta1
   go1.4rc1
   go1.4rc2
   go1.5
   go1.5.1
   go1.5.2
   go1.5.3
   go1.5beta1
   .........
   .........

If you want to install any versions > 1.4, you might get following errors

ERROR: Failed to compile. Check the logs at /home_directory/.gvm/logs/go-go1.5.3-compile.log
ERROR: Failed to use installed version
 
 
##Details Error Message:
 
##### Building Go bootstrap tool.
cmd/dist
ERROR: Cannot find /home_directory/go1.4/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.
./make.bash: line 121: /home_directory/go1.4/bin/go: No such file or directory

In order to solve this problem you will have to go through the following process. Install 1.4 and then export GOROOT_BOOTSTRAP=$GOROOT. After that you can install any version of GO > 1.4+.

gvm install go1.4 --binary
gvm use go1.4 
export GOROOT_BOOTSTRAP=$GOROOT 
gvm install go1.7

Go installation is done. Let’s write first hello world program!!!
In any directory you can open a file and type following code:

package main
 
import "fmt"
 
func main() {
    fmt.Println("hello world!")
}

And, save file as helloworld.go
Build and run the code.

go build helloworld.go
go run hellowordld.go  //it will print hello world!

You are now good to go with GO programming language. I will also cover some other important topic on GO.

IDE for GO

There are some lite IDEs for Linux and OSX. I enlisted couple of them….

 

Dependency Manager

Now a days, almost all languages have their own dependency manager such as composer for PHP, npm for NodeJS, Bundler for Rails application etc.  But, Go doesn’t have anything our of box solution. There are couple of good dependency managers available by different DEV communities… I am mentioning some of them below

Some Important links to learn GO

 

 

Eftakhairul Islam

Hi, I'm Eftakhairul Islam, a passionate Software Engineer, Hacker and Open Source Enthusiast. I enjoy writing about technical things, work in a couple of startup as a technical advisor and in my spare time, I contribute a lot of open source projects.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Read previous post:
Asset Management and Font Awesome Icons in Production Sails App

I am writing this post just to solve a small problem that I've recently experienced while deploying a Sails App...

Close