英文:
$GOPATH error while installing json2csv
问题
我正在运行Linux 3.16.0-4-amd64 x86_64操作系统。我想安装json2csv。
我尝试了以下命令:
sudo go get github.com/jehiah/json2csv
但是出现了以下错误:
package github.com/jehiah/json2csv: 无法下载,$GOPATH未设置。更多详情请参阅:go help gopath
go已经安装了:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
我设置了:
export GOROOT=/usr/bin/go
export GOPATH=$HOME/projects/go
但是我仍然得到相同的错误。
有什么建议吗?
英文:
I'm running Linux 3.16.0-4-amd64 x86_64.
I want to install json2csv.
I try:
sudo go get github.com/jehiah/json2csv
and get:
package github.com/jehiah/json2csv: cannot download, $GOPATH not set. For more details see: go help gopath
go is installed:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
I set:
export GOROOT=/usr/bin/go
export GOPATH=$HOME/projects/go
but I still get the same error.
Any idea?
答案1
得分: 3
原因是当你使用sudo
时,你丢失了一些环境变量。你可以使用-E
选项来保留它。
你可以在这里查看详细信息:
https://linux.die.net/man/8/sudo
但是你不应该使用sudo来执行go get
命令。
顺便说一下,你可以将环境变量保存在.bash_profile
文件中,这样它可以自动加载。
在这种情况下,你应该设置GOROOT
和GOPATH
:
export GOROOT=/usr/local/go
export GOPATH=$HOME/projects/go
请注意,GOROOT
是go的安装目录,而不是go的可执行文件所在的目录。
然后,不使用sudo来执行go get
命令:
go get github.com/jehiah/json2csv
英文:
The reason is that you lost some of your ENV when you use sudo
.
you could use -E
to preserve it.
you can check it out here:
https://linux.die.net/man/8/sudo
But you should not use sudo to go get.
By the way, you could save you env in .bash_profile
, so it can load automatically.
In this case, you should set GOROOT
and GOPATH
with
export GOROOT=/usr/local/go
export GOPATH=$HOME/projects/go
Mind that the GOROOT
is the folder of go, no the binary of go.
then, go get without sudo.
go get github.com/jehiah/json2csv
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论