Multiple GOPATH's in fish shell

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

Multiple GOPATH's in fish shell

问题

我正在使用fish shell。config.fish文件中设置了GOPATH环境变量如下:

set -x GOPATH $HOME/Documents/Programming/go/3rdparty:$HOME/Documents/Programming/go/own

我有两个问题。

第一个问题:无法直接调用3rdparty/bin目录下的可执行文件,比如golocc或者godep。我必须进入该目录并使用./godep等方式来调用。我该如何使godep可以全局调用?

第二个问题:我无法使用cd命令进入$GOPATH目录。执行cd $GOPATH后显示如下错误:

cd: The directory '/Users/xxx/Documents/Programming/go/3rdparty:/Users/xxx/Documents/Programming/go/own' does not exist

我猜测这两个问题都是由于我的GOPATH设置引起的。问题出在哪里呢?

英文:

I'm using fish shell. config.fish has GOPATH environment as:

set -x GOPATH $HOME/Documents/Programming/go/3rdparty:$HOME/Documents/Programming/go/own

I have two problems.

1st: Can't call executables in 3rdparty/bin directly such as golocc or godep. I must go in the directory and call it as ./godep and so on. How can I make godep to be called globally.

2nd: I can't cd to $GOPATH. cd $GOPATH gives

cd: The directory '/Users/xxx/Documents/Programming/go/3rdparty:/Users/xxx/Documents/Programming/go/own' does not exist

I'm guessing both problems occurs because of my GOPATH. What is the problem?

答案1

得分: 2

GOPATH只与Go工具包相关,您需要设置PATH变量。

由于您的GOPATH中有多个文件夹,您需要按照以下方式进行设置:

set -gx PATH $PATH $HOME/Documents/Programming/go/3rdparty
set -gx PATH $PATH $HOME/Documents/Programming/go/own

对于第二个问题,您无法直接这样做,一个解决方法是使用多个变量,例如:

set -gx GOPATH1 $HOME/Documents/Programming/go/3rdparty
set -gx GOPATH2 $HOME/Documents/Programming/go/own
set -gx GOPATH $GOPATH1:$GOPATH2
set -gx PATH $PATH $GOPATH1/bin
set -gx PATH $PATH $GOPATH2/bin

然后您就可以使用$GOPATH1$GOPATH2进行cd操作。

英文:

GOPATH is only relevant to the Go toolkit, you have to set the PATH variable.

Since you have more than 1 folder in your GOPATH you will have to do it like this:

set -gx PATH $PATH $HOME/Documents/Programming/go/3rdparty
set -gx PATH $PATH $HOME/Documents/Programming/go/own

For the second problem, you simply can't do that, on solution is to have multiple variables for example:

set -gx GOPATH1 $HOME/Documents/Programming/go/3rdparty
set -gx GOPATH2 $HOME/Documents/Programming/go/own
set -gx GOPATH $GOPATH1:$GOPATH2
set -gx PATH $PATH $GOPATH1/bin
set -gx PATH $PATH $GOPATH2/bin

Then you will be able to cd $GOPATH1 or $GOPATH2

huangapple
  • 本文由 发表于 2015年8月7日 09:59:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/31868571.html
匿名

发表评论

匿名网友

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

确定