Skip to content

Instantly share code, notes, and snippets.


rb16/GoLang setup

Last active Jun 26, 2018
What would you like to do?
GOlang Setup Environment Linux and OS X
#Set these variables in .bash_profile (OS X) file
export GOPATH=$HOME/workspace
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin

Install Go for OS X (using homebrew).

  • Install Homebrew
    ruby -e "$(curl -fsSL"
    brew update
  • Install GO
    brew install go
  • Create a directory workspace in home folder
    mkdir workspace
  • Setup GOPATH and GOROOT
    cd workspace
    export GOPATH=/Users/`whoami`/workspace

Install Go in linux box

  • Download latest GO from Here
    tar -C /usr/local -xzf go1.9.linux-amd64.tar.gz
  • Set GOPATH and PATH
    mkdir -p ~/workspace; echo "export GOPATH=$HOME/workspace" >> ~/.bashrc
    echo "export PATH=$PATH:$HOME/workspace/bin:/usr/local/go/bin" >> ~/.bashrc
    source ~/.bashrc

Install Go in Windows.

  • Donwload and install lates MSI distributable from
  • create a directory workspace in C:\
  • To make life simple use the default installation path at C:\workspace
  • The installer should put the C:\workspace\bin directory in your PATH environment variable.


  • A workspace is a directory hierarchy with three directories at its root:
    • src contains Go source files,
    • pkg contains package objects, and
    • bin contains executable commands.

Source repository

If your code in a source repository somewhere. then you should use the root of that source repository as your base path inside src. For instance, if you have a bitbucket account at, that should be your base path.

    mkdir -p $GOPATH/src/

Your first program

To Run a simple program, first choose a package path (

 mkdir $GOPATH/src/

where hello is a package directory inside base path. and then create your first hello program (hello.go) inside package.

###Compile and Run

go install $GOPATH/src/



This comment has been minimized.

Copy link

@sudheerit11 sudheerit11 commented Jul 30, 2016

nice article.


This comment has been minimized.

Copy link

@napster11 napster11 commented Jul 30, 2016

Good one ram


This comment has been minimized.

Copy link

@pontiyaraja pontiyaraja commented Feb 1, 2017

its really helpfull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.