英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论