Setting up development environment in golang


As I said in my previous article, we’ll see how to use the $GOROOT, $GOPATH, $GOBIN ENV variables.

If you don’t want to change anything that is already set by default and already have a IDE, you can sure this article.

Just create your projects in ~/go/src

A workspace should always have 3 directories: src, bin and pkg.

src folder holds all your Go projects, bin folder contains the binary files and pkg directory contains Go package objects.


When you install Go on your system, it creates a directory /usr/local/go in UNIX or c:/go in Windows.

This is where Go’s standard library and compiler lives. Whenever you import a package from Go’s standard library, Go looks for package in this directory.

If you want to change this default location you can edit your ~/.bash_profile or ~/.bashrc or ~/.zshrc(if you use zsh)

Just add this export GOROOT=~/Desktop/mygo line to it. But i wouldn’t actually recommend changing this variable unless you really want it.

gopath and gobin:

Whenever Go program hits import statement, it looks for package(s) in Go’s standard library($GOROOT/src). If package is not present there, then Go checks in GOPATH and looks for packages in $GOPATH/src directory

And when you compile your program that object file is placed under $GOBIN

so if you want to change your default workspace:

#set up your ENV
export GOPATH=/Users/Vigneshwar/Desktop/go_workspaces/main
export GOBIN=$GOPATH/bin

#append those variables to the path
#and export it
export PATH

setting up your ide

Sure you can use anything here. It can be vim, emacs to atom and vscode.

I personally like vscode, so I will use that.

The theme I’m using is called “shades of puple” if you’re interested. And for terminal I used something called ‘zsh’ and used ‘agonster’ theme for it.

So for extensions you might only need the ‘go’ extension by microsoft.

So there you have it. Now we can actually start writing some code.


About the author


Add comment

Leave a Reply

By vigneshwar

Most common tags

%d bloggers like this: