Skip to content

Instantly share code, notes, and snippets.

@JohnMurray
Created August 10, 2017 19:44
Show Gist options
  • Save JohnMurray/30d396fa66a9b0fe3dd179c4a5f737f1 to your computer and use it in GitHub Desktop.
Save JohnMurray/30d396fa66a9b0fe3dd179c4a5f737f1 to your computer and use it in GitHub Desktop.
Instructions for setting up GoLang locally

Installing Go

Installation

Change Directory

cd ${HOME}

Install a binary distribution

OSX or Linux

pushd /tmp

# Download the appropriate file
wget https://storage.googleapis.com/golang/go1.8.3.darwin-amd64.tar.gz   # Mac
wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz    # Linux

# install to /usr/local
sudo tar -C /usr/local -xzf go1.8.3.darwin-amd64.tar.gz  # Mac
sudo tar -C /usr/local -xzf go1.8.3.linux-amd64.tar.gz   # Linux

Setup the Workspace

GOPATH

Edit

Edit the appropriate shell file. Likely one of:

${HOME}/.bash_profile   # Mac
${HOME}/.bashrc         # Linux - Bash
${HOME}/.zshrc          # Zsh (Mac & Linux)

And add the following:

export GOPATH="${HOME}/go"
export PATH="/usr/local/go/bin:${GOPATH}/bin:$PATH"

Then create the directory for our $GOPATH:

mkdir -p "${HOME}/go"

Activate:

Source the appropriate shell file (the one edited in the previous step) so we can make sure your setup correctly and create our workspace.

source ${HOME}/.bashrc

Workspace Directories

Create the directories on Unix

The $GOPATH is where all the magic happens with Go. It's both where we pull down dependencies too as well as where we do our development. We'll go over this in the Lunch-and-Learn.

mkdir -p ${GOPATH}/src
mkdir -p ${GOPATH}/pkg
mkdir -p ${GOPATH}/bin
mkdir -p ${GOPATH}/src/github.com/${username}

Check the Go Environment

The last thing is to make sure you can run the following command.

go env

On my machine, I see the following output:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jmurray/projects/go-workspace"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build198393980=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

My go-path is a little different, but this is more or less what you should see. The important parts are to make sure GOPATH poitns to the directory we setup ($HOME/go) and GOROOT points to the correct install of go (/usr/local/go).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment