无法下载,未设置 $GOPATH [英] cannot download, $GOPATH not set
问题描述
我想使用 go get github.com/jehiah/json2csv
安装 json2csv,但我收到此错误:
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
有关如何在 MacOS 上解决此问题的任何帮助?
Any help on how to fix this on MacOS?
推荐答案
[更新:从 Go 1.8 开始,GOPATH
默认为 $HOME/go
,但你可以如果您想了解 GOPATH
布局、自定义它等,仍然会发现这很有用.]
[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.]
官方 Go 站点 讨论 GOPATH 以及如何布置工作区目录.
export GOPATH="$HOME/your-workspace-dir/"
-- 在你的 shell 中运行它,然后将它添加到 ~/.bashrc
或等效的它会在未来为你设置.Go 将在 src/
、bin/
和 pkg/
子目录下安装软件包.如果您想发布到 GitHub,您需要将自己的包放在 $GOPATH/src
下的某个位置,例如 $GOPATH/src/github.com/myusername/
.您可能还需要 export PATH=$PATH:$GOPATH/bin
在您的 .bashrc
中,以便您可以在 $GOPATH
下运行已编译的程序.
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
.
可选地,通过 Rob Pike,您还可以设置 CDPATH
所以 cd
在 bash 中打包目录会更快: export CDPATH=.:$GOPATH/src/github.com:$GOPATH/src/golang.org/x
意味着你可以只输入 cd net/html
而不是 cd $GOPATH/src/golang.org/x/net/html
.
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 您可以将 GOPATH=$HOME
设置为将 Go 的 src/
、pkg/
和 bin/
目录放在你的 homedir 下.这可能很好(例如,您的路径中可能已经有 $HOME/bin
),但当然有些人使用多个工作区等.
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.
这篇关于无法下载,未设置 $GOPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!