Catalogue
Setting Up a Go Development Environment on Mac OS X

Setting Up a Go Development Environment on Mac OS X

🌐 日本語で読む

Environment

  • Mac OS X 10.10.4 Yosemite
  • Go 1.4
  • Eclipse Mars Release (4.5.0)

Overview

As of 2015-08-01

I had been considering using IntelliJ for Go development, but
since it didn’t support Go version 1.4,
I’ll set up GoClipse in Eclipse to get features like code completion working.

Installing Go

1
$ brew install go

If you haven’t installed brew yet, see the following

https://kenzo0107.github.io/2015/02/27/2015-02-28-install-homebrew-on-macosx/

Checking the Go Version

1
2
$ go version
go version go1.4.2 darwin/amd64

Setting Environment Variables

Personally I use ~/.zshrc, but if you don’t have it,
add the following to something like ~/.bash_profile.

1
2
3
4
5
# go
if [ -x "`which go`" ]; then
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
fi

By the way, -x checks whether a file is executable.
In other words, “if [ -x “which go“]” checks whether the which go command can be executed.

In the current local environment, typing which go
gives the following.

1
2
$ which go
/usr/local/bin/go

GOPATH

  • This becomes your workspace. You will create your projects under this directory.
  • This is where things are stored when you run go install or go get.

Checking Go Environment Information

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ go env

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/kenzo/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.4.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.4.2/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
  • When you install go with brew, GOROOT is located under /usr/local/Cellar/.

Applying the Environment Variable Settings

For .zshrc

1
$ source .zshrc

For .bash_profile

1
$ source .bash_profile

Installing GoClipse

Click Help > Install New Software... in the top menu of Eclipse

Configuring the GoClipse Software Location

Select GoClipse and Install

  • Check GoClipse and click the Next > button to proceed with the installation.

  • Go will now appear as a Perspective.

Configuring the GoClipse Paths

That’s all.

Setting Up a Go Development Environment on Mac OS X

https://kenzo0107.github.io/en/2015/08/02/golang-development-on-macosx/

Author

Kenzo Tanaka

Posted on

2015-08-02

Licensed under