How to install GOPATH on Mac OS X 10.10

I installed Go 1.4 on Mac OS X. I used to have Go 1.0. I installed GOROOT and PATH as follows:

Dineshs-MacBook-Air:go-cassandra Dany$ which go /usr/local/go/bin/go Dineshs-MacBook-Air:go-cassandra Dany$ export GOROOT=/usr/local/go/bin/go Dineshs-MacBook-Air:go-cassandra Dany$ export PATH=$PATH:$GOROOT/bin 

Go is set to '/ usr / local / go / bin / go'. And I installed GOPATH as the directory of my src project. I can run go code inside my directory. But when I try to install gocql, I get an error.

 Dineshs-MacBook-Air:go-cassandra Dany$ sudo go get github.com/gocql/gocql package github.com/gocql/gocql: cannot download, $GOPATH not set. For more details see: go help gopath 

Can someone help me with this? Thanks you

EDIT 1: @VonC I also tried another option. I changed GOROOT to the directory where go is installed. But it did not help. And I changed GOPATH.

 Dineshs-MacBook-Air:go-cassandra Dany$ export GOROOT=/usr/local/go Dineshs-MacBook-Air:go-cassandra Dany$ export PATH=$PATH:$GOROOT/bin Dineshs-MacBook-Air:go-cassandra Dany$ export GOPATH=/Users/Dany/Documents/FALL-2013-COURSES/Imp_Data_structures/workspace/go-cassandra Dineshs-MacBook-Air:go-cassandra Dany$ sudo go get github.com/gocql/gocql Password: package github.com/gocql/gocql: cannot download, $GOPATH not set. For more details see: go help gopath Dineshs-MacBook-Air:go-cassandra Dany$ echo $GOPATH /Users/Dany/Documents/FALL-2013-COURSES/Imp_Data_structures/workspace/go-cassandra Dineshs-MacBook-Air:go-cassandra Dany$ ls bin pkg src Dineshs-MacBook-Air:go-cassandra Dany$ 
+8
go gocql
source share
1 answer

Notes:

GOROOT should refer to the folder (where go is installed), and not to go executable

 export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin 

As Dave mentioned in the comments, you do not need to install GOROOT at all in your case.
See Article You do not need to install GOROOT , really .

GOPATH should refer to the folder where you will find src , pkg and bin . (it should not refer directly to the src folder):
See " How to Write Transition Code - Workspace "

Regarding GOPATH :

  • try setting it to ~/.bashrc (using export ).
  • make sure your current bash shell (and not another one like fish )
  • check the output go env .

Do not run sudo go get , as the environment variable used for sudo ( root ) will not be the same as the current user:

 go get github.com/gocql/gocql 

(or you need to do sudo -E bash -c 'go get github.com/gocql/gocql' , but I suspect you don't need root )

See sudo caveat :

Any variables added to these locations will not be displayed when called with the sudo , since sudo has a default environment reset policy and a safe path (this behavior is defined in /etc/sudoers )

+23
source share

All Articles