选择的目录不是 Go SDK 的有效主目录。

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

"The selected directory is not a valid home for Go Sdk"

问题

我正在使用IntelliJ Idea,并使用来自以下网址的google-go-lang-idea-plugin插件:
>https://github.com/mtoader/google-go-lang-idea-plugin/issues/173

当我尝试将我的APT提供的Go安装添加到Go SDK列表时,我遇到了以下错误:

选择的目录不是 Go SDK 的有效主目录。

我尝试将以下目录作为Go SDK根目录添加:

  • /usr/share/go/
  • /usr/share/src/
  • /usr/lib/go/
  • /usr/lib/go/src/
  • /usr/lib/go/pkg/
  • /usr/lib/go/pkg/linux_amd64

有人知道如何解决这个问题吗?我已经在错误跟踪器中评论了各种问题,但维护者声称这个问题在10个月前已经修复。

如果无法解决,有人知道这个插件实际上在寻找什么,以使目录看起来像SDK目录吗?

英文:

I'm using IntelliJ Idea, and the google-go-lang-idea-plugin from:
>https://github.com/mtoader/google-go-lang-idea-plugin/issues/173

When I try to add my APT provided Go installation to the Go SDK list, I get the following error

选择的目录不是 Go SDK 的有效主目录。

I have tried adding the following directories as the Go SDK root

  • /usr/share/go/
  • /usr/share/src/
  • /usr/lib/go/
  • /usr/lib/go/src/
  • /usr/lib/go/pkg/
  • /usr/lib/go/pkg/linux_amd64

Does anyone know how to get this working? I've commented on the various issues in the bugtracker, however the maintainer claimed that this was fixed 10 months ago.

Failing that, does anyone know what this plugin is actually looking for that would make a directory look like the SDK directory?

答案1

得分: 40

在配置Goland IDEA中的goroot路径时,我遇到了这个问题。

选择的目录不是 Go SDK 的有效主目录。
我按照以下方式解决了它

进入GO SDK路径,找到zversion.go文件,然后在文件末尾添加以下内容:

const TheVersion = `go1.17.2`

根据你的情况,你需要更改版本号。

在我的情况下,zversion.go文件的路径是D:\Programs\Go\src\runtime\internal\sys\zversion.go

保存文件,并重新启动Goland IDE,然后配置GOROOT(文件 -> 设置 -> Go -> GOROOT -> + -> local...),选择你的Go根路径并保存。

选择的目录不是 Go SDK 的有效主目录。

英文:

I came this issue when config goroot path in goland idea.

选择的目录不是 Go SDK 的有效主目录。
I solve it as follows,

Go the GO SDK path and find zversion.go, then append the file with

> const TheVersion = `go1.17.2`

. You need to change the version according to you case.

In my case the sversion.go path is located at D:\Programs\Go\src\runtime\internal\sys\zversion.go.

Save the file, and restart the goland ide, then config the GOROOT (File -> setting -> Go -> GOROOT -> + -> local...), select you Go root path and save it.

选择的目录不是 Go SDK 的有效主目录。

答案2

得分: 5

addon:
在go1.18.4上遇到了相同的问题,只需要在${GOROOT}/src/runtime/internal/sys/zversion.go中添加以下代码行:

const TheVersion = `go1.18`
英文:

addon:
got the same problem on go1.18.4, just need to add this line of code in
${GOROOT}/src/runtime/internal/sys/zversion.go

const TheVersion = `go1.18`

答案3

得分: 3

原文翻译如下:

原来 google-go-lang-idea-plugin 需要与默认的 apt 安装产生的文件夹结构稍有不同。要修复这个问题:

# mkdir /usr/lib/go/bin
# ln -s /usr/bin/go    /usr/lib/go/bin/go
# ln -s /usr/bin/godoc /usr/lib/go/bin/godoc
# ln -s /usr/bin/gofmt /usr/lib/go/bin/gofmt
英文:

It turns out that google-go-lang-idea-plugin requires a slightly different folder structure than the default apt install produces. To fix it:

# mkdir /usr/lib/go/bin
# ln -s /usr/bin/go    /usr/lib/go/bin/go
# ln -s /usr/bin/godoc /usr/lib/go/bin/godoc
# ln -s /usr/bin/gofmt /usr/lib/go/bin/gofmt

答案4

得分: 2

步骤1:打开命令提示符(cmd)。

步骤2:运行以下命令
=> go env

步骤3:找到GOROOT,并根据该GOROOT路径选择Go SDK的目录。

英文:

Step 1: Open cmd

Step 2: Run below command
=> go env

Step 3: Find GOROOT and according this GOROOT path select directory for Go Sdk.

答案5

得分: 1

我刚在IntelliJ 2016.1.3Go 1.5上遇到了同样的问题。

我之前安装了IntelliJ Go插件,并且一段时间前安装了GO 1.5,一切都正常工作。现在我检查了一下,突然间,我确定我没有删除它,我的系统中没有GO 1.5了。但是谁知道呢,我有一段时间没有使用go了,所以我可能已经删除了它。

无论如何,在进行了一些调试之后,以下步骤帮助了我:

  1. 安装最新的Go版本(对我来说是1.6.3)。按照https://golang.org/doc/install上的说明进行操作。
  2. 更新IntelliJ中的Go插件!!!
  3. 在IntelliJ中为项目设置SDK:文件 -> 项目结构 -> 项目 -> 在项目SDK下添加一个新的SDK并导航到您的go安装位置
  4. 点击应用,然后点击确定
英文:

So I just had this exact problem on IntelliJ 2016.1.3 with Go 1.5.

I had installed the IntelliJ Go Plugin a while ago and installed GO 1.5 a while back, and it all worked fine. Now i checked and suddenly, I'm sure I didn't remove it, GO 1.5 was gone from my system. But who knows, I haven't worked with go for a bit, so I might have removed it.

Anyway, after a bit of debugging, the following steps helped me:

  1. Install the most current Go version (currently for me 1.6.3). Follow the instructions on https://golang.org/doc/install
  2. Update the Plugin for Go in IntelliJ !!!
  3. Set the SDK in IntelliJ for the project:File -> Project Structure -> Project -> under Project SDK add a New SDK and navigate to your go installation.
  4. Click Apply and then Ok

答案6

得分: 1

当我使用go1.18并在GOROOT路径下的/src/runtime/internal/sys/zversion.go中添加以下代码时,遇到了相同的问题:

const TheVersion = `go1.18`

但是它没有起作用。对于go1.17,类似的操作是有效的。

英文:

I met the same problem when using go1.18 and add

const TheVersion = `go1.18`

in /src/runtime/internal/sys/zversion.go under GOROOT PATH

but it didn't work. Similar action for go1.17, it worked.

答案7

得分: 0

goland 2022.3.2 golang 1.19.5

在添加goSDK时,IDE将检查以下项目:
1、dir/bin/go.exe 是否存在?
2、dir/bin/go.exe 是否可执行?
3、dir/VERSION

请不要更改 dir/src/runtime/internal/sys/zversion.go 文件。

英文:

goland 2022.3.2 golang 1.19.5

The IDE will check the following items when adding goSDK
1、dir/bin/go.exe exists?
2、dir/bin/go.exe can execute?
3、dir/VERSION

dir/src/runtime/internal/sys/zversion.go don't change

答案8

得分: 0

如上面的答案所说,当添加Go SDK时,Goland会检查三个项目。我遇到了类似的情况,因为我在bin目录中将"go"命令重命名为"go20",以保留多个Go环境的版本。通过将版本值添加到文件中,并保存两个可执行命令"go"和"go20",然后将go20添加到系统路径中,问题得以解决,使得Goland能够找到初始的go命令。如果在添加变量后问题仍然存在,请检查bin目录。

英文:

As the answer above said, goland checks three items when adding go sdk. I got the similar situation because i renamed the 'go' command to 'go20' in bin directory, for keeping multi versions of go environments. The problem was solved by adding version val into the file and saving two executable commands 'go' and 'go20' and just add go20 into the system path, made goland could find the initial go command. If your problem still exists after adding the var, check the bin directory.

huangapple
  • 本文由 发表于 2013年10月1日 13:08:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/19108421.html
匿名

发表评论

匿名网友

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

确定