n179911
n179911

Reputation: 20291

How to set GOPATH on MAC after installing go1.4.1.darwin-amd64-osx10.8.pkg

I have run go1.4.1.darwin-amd64-osx10.8.pkg to install go on my MAC. It install go in /usr/local/go/bin/go.

Can you tell me what should my GOPATH set to? I tried '/usr/local/go' and '/usr/local/go/bin/go'. But both does not seem to be the right path.

Thank you.

Upvotes: 1

Views: 5054

Answers (2)

Anshu
Anshu

Reputation: 1327

Try this

First you can check the golang is install or not. Run go env

After that you can show the list of go env variables..

then you check where you can install the go

after that set $GOPATH

like:- export GOPATH=/var/projects/go

and also set $GOBIN

like:- export =$GOPATH/bin

Upvotes: 1

Root Fool
Root Fool

Reputation: 324

GOPATH is an environmental variable used to define the location of your workplace directory. It's used by the Go tools for various reasons.

For example:

go get -u github.com/nsf/gocode

  • will download the source code and place it at $GOPATH/src/github.com/nsfs/gocode
  • Compile that source code and place the binary at $GOPATH/bin
  • Place symbol and package information at $GOPATH/pkg/architecture/github.com/nsfs

The path is also used in other tools:

  • go build github.com/nsf/gocode
  • go install github.com/nsfs/gocode

github.com/nsfs/gocode in the above commands is resolved automatically to $GOPATH/src/github.com/nsfs/gocode and thus you can run these commands without actually being in your workplace (the point of $GOPATH)

The $GOPATH location for your workplace directory can be put anywhere on your machine, but it must minimally have 3 folders (because go get and other tools need these folders).

  1. bin
  2. pkg
  3. src

This environmental variable can be set like any other environmental variable. If you're using go from the Terminal.app, you can set it by opening the file:

vi ~/.bashrc

and then setting it

export GOPATH=~/goworkplace

~/goworkplace is a location to the workplace directory with those 3 folders. It can be anywhere on your system, such as, ~/Development/goworkplace, ~/Desktop/goworkplace, as long as it has those 3 folders

For information, take a look at this: https://golang.org/doc/code.html

Upvotes: 2

Related Questions