英文:
Intellij Golang cannot find a module
问题
我正在使用IntelliJ的Golang插件,在为模块和项目设置了GO SDK之后。我尝试编辑项目的配置。当我点击编辑配置时,在模块下拉框中,它显示没有模块。似乎配置无法找到该模块。我是否漏掉了什么?为了使Go SDK在Intellij中工作,我已经执行了以下命令:
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
英文:
I am using Golang plugin for IntelliJ, after set the GO Sdk for the module and project. I tried to edit configuration for the project. When I click the edit configuration, in module dropdown box, it shows no module. it seems the configuration cannot find the module. Anything that I missed? I have issue the following command in order to make Go SDK work in Intellij.
# 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
答案1
得分: 3
在最新版本的IntelliJ中(这里是Ultimate 2019.1.3的截图),你可以在Preferences
(首选项)-> Language & Frameworks
(语言和框架)-> Go
(Go语言)-> GOROOT
/GOPATH
(Go根目录/Go路径)中找到GOROOT和GOPATH。
-
在你的系统中安装Golang(我使用了brew):
自从OSX ElCapitan以来,OSX禁止访问
/bin
目录,这会导致使用默认设置编译项目时出现问题,并出现以下错误:无法运行程序
/bin/go
(在目录/Users/XXX/go/src/YYY/ZZZ/service
中):错误=2,没有该文件或目录因此,可以通过更新GO首选项来解决这个问题。
-
打开IntelliJ和你的Go项目,并在项目中更新GOROOT。
-
如果你有自定义的GOPATH目录,请同时更新它。
-
点击运行你的Go程序。
英文:
In the recent version of IntelliJ (here is screenshot from Ultimate 2019.1.3) you can find the GOROOT and GOPATH in Preferences
-> Language & Frameworks
-> Go
-> GOROOT
/GOPATH
.
-
Install to Golang in your system (I used brew):
> Since OSX ElCapitan, the OSX forbid access to
/bin
directory, which would cause problems with compiling the project with the default settings and having error like:
>
> Cannot run program "/bin/go" (in directory "/Users/XXX/go/src/YYY/ZZZ/service"): error=2, No such file or directory
>
> So this should be solved by updating GO preferences. -
Open IntelliJ and your go project and update GOROOT in your project
-
If you have a custom directory of GOPATH do update it as well.
-
Click to run your go program.
答案2
得分: 2
这对我有效:
- 关闭 GoLand。
- 导航到项目根目录,备份并删除 .idea 目录。
- 再次打开 IDE。
来源:https://youtrack.jetbrains.com/issue/GO-11854
英文:
this works for me:
- Close GoLand.
- Navigate to the project root, backup and delete .idea
directory. - Open the IDE again.
答案3
得分: 1
请尝试使用该插件的最新版本,看看问题是否仍然存在。
请注意,您不需要链接任何内容,只需设置您的$GOROOT
环境变量(或者不设置,如本文中所述),以及您的$GOPATH
。
英文:
Try the recent latest releases of that plugin, to see if the issue persists.
Note that you shouldn't have to link anything, just set your $GOROOT
environment variable (or not, as mentioned in this article), and your $GOPATH
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论