简体   繁体   中英

"The selected directory is not a valid home for Go 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?

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

在此处输入图像描述 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.

在此处输入图像描述

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

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

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.

You seem to have selected the GOPATH , but the tool wants the GOROOT ! Look at this test that you fail:

https://github.com/mtoader/google-go-lang-idea-plugin/blob/master/src/ro/redeul/google/go/sdk/GoSdkUtil.java#L84

I can only see linux_amd64 barely under your popup which indicates a GOPATH to me.

In general, the trend nowadays is to install packages/tools (especially when they're so young like GO) as non-root users and in your home directory and adjust $PATH and $GOPATH in your environment instead of installing it globally. This will make it much easier to upgrade and change versions. I'd recommend to place go in ~/usr/local/go and your GOPATH into ~/gopath . Then point IntelliJ to ~/usr/local/go

插件:在go1.18.4上遇到同样的问题,只需要在${GOROOT}/src/runtime/internal/sys/zversion.go中添加这行代码

const TheVersion = `go1.18`

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM