GO环境变量PATH被搞乱了。

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

GO env variable PATH got messed up

问题

我正在尝试使用以下命令使用go安装软件包:

go install fyne.io/fyne/v2/cmd/fyne@latest

这与指令中所说的一样,但理想情况下应该返回以下消息:

Users/name/go/bin/fyne

但是,当我输入该命令时,出现以下问题:

fyne未找到

软件包作者告诉我,您可能没有将GOBIN路径添加到PATH变量中。我怀疑这是golang/go#39531问题。

当我在命令行中执行导出命令时:

export

我得到了以下Golang路径:

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin

我认为上述路径可能出错了,因为我已经多次安装和卸载,并使用以下命令进行卸载:

我已经通过以下方式卸载:

$ sudo rm -rf /usr/local/go

$ sudo rm /etc/paths.d/go

尽管我尝试通过以下方式更改:

vim ~/.zshrc

添加一行:

export PATH=$PATH:$(go env GOPATH)/bin

但仍然不起作用。

解决添加GOBIN到路径的最佳方法是什么?

谢谢!

英文:

I am trying to install package using go with below command:

go install fyne.io/fyne/v2/cmd/fyne@latest

This is the same as what the instruction said but ideally it should return below message

Users/name/go/bin/fyne
But when I enter the command it has below issue

fyne not found

The package author told me You likely don’t have the GOBIN path added to your PATH variable. I suspect it is golang/go#39531 that comes back to bite you.

When I execute export in the command line:

export

I am getting the below Golang path:

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin

I thought the path above was messed up because I have done multiple times of installing and uninstalling with uninstalling using below commands

I've done uninstall via:

$ sudo rm -rf /usr/local/go

$ sudo rm /etc/paths.d/go

Althought I've tried to change via:

vim ~/.zshrc

Add a line

export PATH=$PATH:$(go env GOPATH)/bin

It's still not working.

What’s the best approach to resolve adding GOBIN to path?

Thanks!

答案1

得分: 1

如果你只需要将GOBIN添加到PATH中,可以执行以下操作:

PATH=$PATH:$(go env GOBIN)

由于GOBIN通常是~/go/bin,你通常可以只执行以下操作:

PATH=$PATH:~/go/bin

你可以将该命令添加到~/.zshrc中,以使其持久化,并立即执行它:

source ~/.zshrc

之后,如果你的shell仍然无法找到fyne,请检查当前PATH的内容是否包含GOBIN

echo $PATH

如果没有包含,说明在将GOBIN添加到PATH时出现了问题。

英文:

If all you need is to add GOBIN to PATH, do:

PATH=$PATH:$(go env GOBIN)

Since GOBIN often is ~/go/bin, you usually could get away with just:

PATH=$PATH:~/go/bin

You can add that command to ~/.zshrc to make it persistent and then source it to execute it immediately:

source ~/.zshrc

After that, if your shell remains unable to find fyne, check that current PATH content includes GOBIN with:

echo $PATH

If it doesn't, something went wrong when adding GOBIN to PATH.

huangapple
  • 本文由 发表于 2022年8月4日 06:08:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/73228313.html
匿名

发表评论

匿名网友

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

确定