I want to install json2csv using go get github.com/jehiah/json2csv
but I receive this error:
package github.com/jehiah/json2csv: cannot download
Your $GOROOT
should not be set up.
You $GOPATH
should be set to $HOME/go
by typing export $GOPATH=$HOME/go
Please type export GOROOT=""
to fix your problem.
Just do export GOPATH="/whatever/you/like/your/GOPATH/to/be"
.
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.
[Update: as of Go 1.8, GOPATH
defaults to $HOME/go
, but you may still find this useful if you want to understand the GOPATH
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 under src/
, bin/
, and pkg/
, 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 want export 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 to cd
to package dirs in bash: export CDPATH=.:$GOPATH/src/github.com:$GOPATH/src/golang.org/x
means you can just type cd net/html
instead of cd $GOPATH/src/golang.org/x/net/html
.
Keith Rarick notes you can set GOPATH=$HOME
to put Go's src/
, pkg/
and bin/
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:
sudo env GOPATH=$HOME/goWorkDirectory go build ...
Even glide
was giving me the GOPATH 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.
sudo env GOPATH=$HOME/goWorkDirectory glide install
Hope this helps someone.
I had to run an application as root (to open a webserver on port 80), this produced the error for me, because the sudo user has a different environment than the normal user, hence GOPATH was not set.
If someone else is having this problem, add -E
to the command, this will preserve the user environment.
sudo -E go run main.go
For more infos see discussion here: Google Groups – GOPATH Problem