英文:
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。
所以我创建了~/go
目录,然后更新了我的.zshrc
文件,导出了GOPATH
和GOROOT
环境变量,尽管当我运行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.
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.
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。
英文:
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.
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论