使用fish shell与Go一起使用时,在运行`go install /path/to/src`时出现错误。

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

Using Go with fish fish shell - error when running `go install /path/to/src`

问题

我正在遵循golang文档中的“如何编写代码”部分,这里。我还在使用fish shell。

我已经按照教程设置了正确的环境变量(GOPATH和PATH),但是在我的安装中无法使用命令go install github.com/user/hello。我遇到了一个错误:

无法加载包:包github.com/user/hello:导入“github.com/user/hello”时找不到包

英文:

I am following the "How to Write Code" portion of the golang docs, here. I am also using fish fish shell.

I have followed the tutorial and set the proper environment variables (GOPATH and PATH) but I can't get the command go install github.com/user/hello to work with my installation.
I am getting an error:
> can't load package: package github.com/user/hello: import
> "github.com/user/hello": cannot find package

答案1

得分: 52

我实际上错误地设置了我的环境变量。
具体来说,在我的~/.config/fish/config.fish文件中设置GOPATH时,我需要导出该变量。

将以下行添加到你的config.fish文件中,以便fish shell使用Go:
set -x GOPATH $HOME/path/to/your/workspace

注意到**-x**。这就是缺失的部分。

英文:

I had, in fact, incorrectly set my environment variables.
Specifically, when setting GOPATH in my ~/.config/fish/config.fish file I needed to export the variable.

Put these lines in your config.fish for fish shell to use Go:
set -x GOPATH $HOME/path/to/your/workspace

Note the -x. That was what was missing.

答案2

得分: 4

比编辑config.fish文件更好的方法是在你的shell中使用set命令,使用--universal(持久化)和-x(导出)参数,像这样运行:

set --universal -x GOPATH $HOME/path/to/goworkspace
英文:

Even better than editing the config.fish file, run set command with --universal (to persist) and -x (export) in your shell like so:

set --universal -x GOPATH $HOME/path/to/goworkspace

huangapple
  • 本文由 发表于 2013年8月28日 11:37:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/18478995.html
匿名

发表评论

匿名网友

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

确定