Setting up your machine for Go

GoLanger
3 min readNov 4, 2016

--

Those who are not aware one of the powerful programming language Go, then you can read my previous post about Starting with Go.

Here I’m going to explaining about how we can set up our machine or development environment to set up support for Go.

There are many ways to install and configure Go environment in your system, so I’m explaining the three most common ways for it.

Install from Source Code

Because some parts of Go are written in Plan 9 C and AT&T assembler, you have to install a C compiler before taking the next steps.

On a mac, if you have installed Xcode, you already have a compiler.

On Unix-like systems, you need to install gcc or a similar compiler. For example using the package manager apt-get (included with Ubuntu), one can install the required compilers as follows:

sudo apt-get install gcc libc6-dev

On windows systems, you need to install MinGW in order to install gcc. Don’t forget to configure your environment variables after installation has completed.

The Go team uses Mercurial to manage their source code, so you need to install this in order to download the Go source code.

At this point, execute following commands to clone the Go source code and compile it. (It will clone the source code into current directory, change work path before you continue to next steps.)

hg clone -u release https://code.google.com/p/go
cd go/src
./all.bash

A successful installation will end with message “ALL TESTS PASSED.”

On windows systems you can achieve the same by running all.bat

If you are using Windows, the installation packages set environment variables automatically. In Unix-like systems, you need to set the variables manually as follows.

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

Once you are done with above steps, then you are all set to start Go programming.

You can check whether Go is installed and configured correctly using:

go help
This will be the screen if Go is installed and configured correctly.

Using standard installation packages

Mac
Go to download page and choose xxx.darwin-amd64.pkg to download the package file and install it using standard methods. Once the installation is completed you can check it using go version as I mentioned above.

Linux
Go to download page and choose the package depends on your operating system, if it’s 32-bit system then chose xxx.linux-386.tar.gz, otherwise a 64-bit version xxx.linux-amd64.tar.gz. Extract the archive to the standard / custom location and configure the path variables.

Windows
Go to download page and choose the package depends on your operating system, if it’s 32-bit system then chose xxx.windows-386.msi, otherwise a 64-bit version xxx.windows-amd64.msi. Install using the msi installer and verify the installations.

Using third-party tools

GVM
GVM is a Go-multi-version control developed by third party developers, like rvm for Ruby. It’s quite easy, type the following command to install GVM.

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

Then we will be able to install Go using following commands.

gvm install go1.4
gvm use go1.4 [--default]

After this you’re all set to rock on.

apt-get
Ubuntu is one of the most popular linux distro, and it uses apt-get to manage packages. We can install Go using following commands.

sudo add-apt-repository ppa:ubuntu-lxc/lxd-stable
sudo apt-get update
sudo apt-get install golang

Homebrew
Homebrew is a software management tool commonly used in Mac to manage packages.

If you don’t have brew in your system, you can install it using following command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then we will be able to install Go using following commands.

brew install go

You’re all ready for an awesome experience with Go.

Programming with Go

--

--