I want to install json2csv using go get github.com/jehiah/json2csv
but I receive this error:
package github.com/jehiah/json2csv: cannot download, $GOPATH not set. For more details see: go help go path
Any help on how to fix this on MacOS?
I want to install json2csv using go get github.com/jehiah/json2csv
but I receive this error:
package github.com/jehiah/json2csv: cannot download, $GOPATH not set. For more details see: go help go path
Any help on how to fix this on MacOS?
[Update: as of Go 1.8,
GOPATH
defaults to$HOME/go
, but you may still find this useful if you want to understand theGOPATH
layout, customize it, etc.]The official Go site discusses GOPATH and how to lay out a workspace directory.
export GOPATH="$HOME/your-workspace-dir/"
-- run it in your shell, then add it to~/.bashrc
or equivalent so it will be set for you in the future. Go will install packages undersrc/
,bin/
, andpkg/
, subdirectories there. You'll want to put your own packages somewhere under$GOPATH/src
, like$GOPATH/src/github.com/myusername/
if you want to publish to GitHub. You'll also probably wantexport PATH=$PATH:$GOPATH/bin
in your.bashrc
so you can run compiled programs under$GOPATH
.Optionally, via Rob Pike, you can also set
CDPATH
so it's faster tocd
to package dirs in bash:export CDPATH=.:$GOPATH/src/github.com:$GOPATH/src/golang.org/x
means you can just typecd net/html
instead ofcd $GOPATH/src/golang.org/x/net/html
.Keith Rarick notes you can set
GOPATH=$HOME
to put Go'ssrc/
,pkg/
andbin/
directories right under your homedir. That can be nice (for instance, you might already have$HOME/bin
in your path) but of course some folks use multiple workspaces, etc.(for MAC)
I tried all these answers and, for some still unknown reason, none of them worked.
I had to "force feed" the GOPATH by setting the environment variable per every command that required it. For example:
Even
glide
was giving me theGOPATH not set
error. Resolved it, again, by "force feeding": I tried all these answers and, for some still unknown reason, none of them worked.I had to "force feed" the GOPATH by setting the environment variable per every command that required it.
Hope this helps someone.
This problem occured to me in raspberry pi. I had logged in through VNC client The problem persisted despite setting and exporting the GOPATH. Then Ran the "go get" command without sudo and it worked perfectly.
Run 'go env' and see where your GOPATH is currently pointing towards. If you change to that directory, your 'go get..etc' command should work.
Watch a Video
In general, I always recommend this official video from Go to get a quick overview on the matter:
http://www.youtube.com/watch?v=XCsL89YtqCs
It's easier to be shown than to be told.
@jwfearn paraphrased the important part of the video:
If you run into this problem after having
$GOPATH
set up, it may be because you're running it with an unsupported shell. I was usingfish
and it did not work, launching it withbash
worked fine.