为什么在 GoLand 中 /user/local/go 没有被识别为 Go SDK?

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

Why /user/local/go isn't recognized as a Go SDK in GoLand

问题

我正在尝试设置GoLand以使用WSL 2,就像这个指南中所述:https://www.jetbrains.com/help/go/how-to-use-wsl-development-environment-in-product.html

我已经按照GoLang网站上的Linux说明在Ubuntu发行版中安装了Go,并且go version输出了我下载的版本,所以Go在WSL内部应该是正常工作的。

所以现在我尝试在GoLand中创建一个新项目,但是我遇到了错误,这些错误似乎是由于SDK没有加载到GoLand中引起的。指南对此没有提供太多指导,所以我尝试添加一个本地SDK。

当我选择/usr/local/go时,会出现一个错误,提示它不是一个有效的SDK。
为什么在 GoLand 中 /user/local/go 没有被识别为 Go SDK?

所以我创建了~/go目录,然后更新了我的.zshrc文件,导出了GOPATHGOROOT环境变量,尽管当我运行go env时它们已经显示出来了,但这样做可以让它们在简单的env调用中显示出来。

但是我仍然遇到了上面的无效SDK错误。

在指南中是否有我遗漏的配置步骤?我看到了这篇旧帖子,关于创建符号链接来模拟预期的目录结构。我没有这样做,因为这是一个非常旧的帖子,有评论说这个问题已经修复了,而且这似乎是一个非常奇怪的解决方案。

英文:

I'm trying to setup GoLand to use WSL 2 as in this guide: https://www.jetbrains.com/help/go/how-to-use-wsl-development-environment-in-product.html

I've installed Go in the Ubuntu distro following the linux instructions on the GoLang website, and go version prints outs the version I downloaded, so it appears that Go is working inside WSL.

为什么在 GoLand 中 /user/local/go 没有被识别为 Go SDK?

So now I tried to create a new project in GoLand, and I'm getting errors, which appear to come from the fact that the SDK isn't loaded in GoLand. The guide doesn't offer much guidance on this, so I just tried to add a local SDK.

When I select /usr/local/go I get an error that it's not a valid SDK.
为什么在 GoLand 中 /user/local/go 没有被识别为 Go SDK?

So I created the ~/go directory, and then updated my .zshrc file to export the GOPATH and GOROOT environment variables, even though they already showed up when I ran go env, doing this got them to show up on a simple env call.

But I'm still getting the invalid SDK error like above.

Is there a configuration step I'm missing that isn't spelled out in the guide? I came across this old post about creating symlinks to fake the expected directory structure. I haven't done this because it's a really old post, has comments that say this has been fixed, and seems like a really odd solution.

答案1

得分: 2

在接下来的2021.3版本中,将支持在WSL2中使用Go SDK,请参阅GO-10618

2021年10月更新。

目前,2021.3版本已进入早期访问计划。如果项目位于WSL2上,GoLand建议在WSL2挂载上选择Go SDK。

为什么在 GoLand 中 /user/local/go 没有被识别为 Go SDK?

英文:

Support for Go SDK in WSL2 will be available in the next 2021.3 release, please see GO-10618.

October 2021 update.

2021.3 reaches Early Access Program at the moment. GoLand suggests selecting Go SDK on WSL2 mount if the location of the project is on WSL2 as well.

为什么在 GoLand 中 /user/local/go 没有被识别为 Go SDK?

答案2

得分: 0

我在我的Debian机器上遇到了这个问题,而且我没有使用WSL2。我发现问题的实际原因是Goland无法读取/usr/local/go/bin目录,这是由于权限不足造成的。

一个可能的解决方案是以root身份运行goland.sh脚本。该脚本可以在Goland IDE文件夹的bin/goland.sh目录中找到。以下是一个简单的命令,以root身份运行Goland:
export HISTIGNORE='*sudo -S*' && echo "sudo-password-here" | sudo -S /absolute-path-to-goland.sh

export HISTIGNORE='*sudo -S*'告诉bash历史记录忽略将匹配sudo -S*的任何命令缓存到bash历史记录中。这样,你的sudo密码就不会保存到bash历史记录文件中。

echo "sudo-password-here" |将你的sudo密码作为输入传递给下一个命令。

sudo -S告诉bash从stdin读取密码提示的输入,这是通过echo命令提供的。

另外,你也可以安装最新版本的Goland。希望它不会有这个bug。

英文:

I experienced this on my Debian machine and I wasn't using WSL2. I found that the actual cause of the issue is that Goland is unable to read the directory /usr/local/go/bin due to inadequate permission.

A possible solution is to run the goland.sh script as root. The script can be found in the bin/goland.sh directory of the Goland IDE folder. Here is a simple command to do run Goland as the root
export HISTIGNORE='*sudo -S*' && echo "sudo-password-here" | sudo -S /absolute-path-to-goland.sh

export HISTIGNORE='*sudo -S*' tells bash history to ignore caching any command matching sudo -S* to bash history. This way, your sudo-password isn't saved into the bash-history file.

echo "sudo-password-here" | pipes your sudo password as input to the next command.

sudo -S tells bash to read input for password prompt from stdin, which has been provided through the echo command.

Alternatively, you can just install the latest version of Goland. Hopefully, it doesn't come with this bug

huangapple
  • 本文由 发表于 2021年9月24日 05:01:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/69306846.html
匿名

发表评论

匿名网友

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

确定