Skip to content

Instantly share code, notes, and snippets.

@pontiyaraja pontiyaraja/GoSetup forked from rb16/GoLang setup
Created Aug 4, 2016

Embed
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 (use homebrew).

  • Install Homebrew
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    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

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

###Workspaces

  • 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 bitbucket.org/user, that should be your base path.

    mkdir -p $GOPATH/src/bitbucket.org/user

###Your first program To Run a simple program, first choose a package path (bitbucket.org/user/hello)

 mkdir $GOPATH/src/bitbucket.org/user/hello

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/bitbucket.org/user/hello
$GOPATH/bin/hello

###IDE

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.