在安装json2csv时遇到了$GOPATH错误。

huangapple go评论124阅读模式
英文:

$GOPATH error while installing json2csv

问题

我正在运行Linux 3.16.0-4-amd64 x86_64操作系统。我想安装json2csv。

我尝试了以下命令:

  1. sudo go get github.com/jehiah/json2csv

但是出现了以下错误:

  1. package github.com/jehiah/json2csv: 无法下载,$GOPATH未设置。更多详情请参阅:go help gopath

go已经安装了:

  1. GOARCH="amd64"
  2. GOBIN=""
  3. GOCHAR="6"
  4. GOEXE=""
  5. GOHOSTARCH="amd64"
  6. GOHOSTOS="linux"
  7. GOOS="linux"
  8. GOPATH=""
  9. GORACE=""
  10. GOROOT="/usr/lib/go"
  11. GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
  12. CC="gcc"
  13. GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
  14. CXX="g++"
  15. CGO_ENABLED="1"

我设置了:

  1. export GOROOT=/usr/bin/go
  2. export GOPATH=$HOME/projects/go

但是我仍然得到相同的错误。

有什么建议吗?

英文:

I'm running Linux 3.16.0-4-amd64 x86_64.
I want to install json2csv.

I try:

  1. sudo go get github.com/jehiah/json2csv

and get:

  1. package github.com/jehiah/json2csv: cannot download, $GOPATH not set. For more details see: go help gopath

go is installed:

  1. GOARCH="amd64"
  2. GOBIN=""
  3. GOCHAR="6"
  4. GOEXE=""
  5. GOHOSTARCH="amd64"
  6. GOHOSTOS="linux"
  7. GOOS="linux"
  8. GOPATH=""
  9. GORACE=""
  10. GOROOT="/usr/lib/go"
  11. GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
  12. CC="gcc"
  13. GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
  14. CXX="g++"
  15. CGO_ENABLED="1"

I set:

  1. export GOROOT=/usr/bin/go
  2. 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文件中,这样它可以自动加载。


在这种情况下,你应该设置GOROOTGOPATH

  1. export GOROOT=/usr/local/go
  2. export GOPATH=$HOME/projects/go

请注意,GOROOT是go的安装目录,而不是go的可执行文件所在的目录。

然后,不使用sudo来执行go get命令:

  1. 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

  1. export GOROOT=/usr/local/go
  2. export GOPATH=$HOME/projects/go

Mind that the GOROOT is the folder of go, no the binary of go.

then, go get without sudo.

  1. go get github.com/jehiah/json2csv

huangapple
  • 本文由 发表于 2016年11月22日 21:26:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/40743087.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定