GOPATH为空(Gogland IDE)

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

GOPATH is empty (Gogland IDE)

问题

我对Go和Gogland还不太熟悉。我刚刚下载了'go1.8.3.windows-amd64.msi',将其安装在C盘,然后开始在记事本中编写程序,最后通过终端运行它。

我在使用Gogland时遇到了一些问题。我有intelliJ IDEA Ultimate,但被要求使用Gogland。我不知道这是否是正确的决定。
你可能想就此向我提供建议。
我刚刚创建了一个新项目,给它起了一个名字,并添加了一个包含简单helloworld代码的go文件。
但它显示了一个错误信息"GOPATH为空"。

如你所见,在package myfirstproject的上方有一条消息。

如何解决这个问题?我需要对环境变量做些什么。PATH环境变量已经设置为'C:\Go\bin'。

当我点击错误消息时,它要求我配置GOPATH。

英文:

I am pretty new to Go and Gogland. I just downloaded 'go1.8.3.windows-amd64.msi', installed it in C Drive and then started writing my programs in a notepad and then finally running it from a terminal.

I am facing some issues with Gogland. I have intelliJ IDEA Ultimate But I have been asked to use Gogland. I do not know whether this is the correct decision.
You may want to advise me on the same.
I just created a new project, gave it a name and added a go file into it which has simple helloworld code.
But it shows me an error "GOPATH is empty".

GOPATH为空(Gogland IDE)

As you could see the message at the top, just above the line package myfirstproject.

How to resolve it? Do I need to do something with environment variables. The PATH environment variable is already set to 'C:\Go\bin'.

When I click on the error message it asks me to configure GOPATH.

GOPATH为空(Gogland IDE)

答案1

得分: 18

截至Go 1.8版本,GOPATH的默认值是/go。

GOPATH是你的源代码所在的位置。你可以使用默认的路径,也可以使用自定义的路径,例如,我使用的是D:\go。

IDE没有检测到GOPATH,因为没有设置。当你下载Go时,也会提供安装说明,请参考那些说明。

英文:

As of Go 1.8, the default GOPATH value is <your-home-dir>/go.

GOPATH is where your source code will live. You can either use the default one or use a custom one, for example, I use D:\go.

The IDE has not detected the GOPATH because none was set. When you download Go you are also presented with the installation instructions, please have a look at that as well.

答案2

得分: 1

检查目录~/go是否存在(对于Windows来说是%USERPROFILE%/go)。如果不存在,则创建它。

TLDR:

Go工具期望源代码具有特定的布局。GOROOTGOPATH是环境变量,用于定义这个布局。

GOROOT是一个变量,用于定义Go SDK的位置。除非您计划使用不同的Go版本,否则不需要更改此变量。

GOPATH是一个变量,用于定义您的工作区的根目录。默认情况下,工作区目录是您用户主目录中名为go的目录(对于Linux和MacOS来说是~/go,对于Windows来说是%USERPROFILE%/go)。GOPATH存储您的代码库和所有开发所需的文件。您可以通过配置不同的作用域来使用其他目录作为工作区的GOPATHGOPATH是您的工作区根目录,包含以下文件夹:

src/:Go源代码的位置(例如,.go、.c、.g、.s)。

pkg/:编译的包代码的位置(例如,.a)。

bin/:由Go构建的编译可执行程序的位置。

要在GoLand中更改GOPATH,请参见这里

英文:

Check if the directory ~/go exists (%USERPROFILE%/go for Windows). If not, create it.

TLDR:

Go tools expect a certain layout of the source code. GOROOT and GOPATH are environment variables that define this layout.

GOROOT is a variable that defines where your Go SDK is located. You do not need to change this variable, unless you plan to use different Go versions.

GOPATH is a variable that defines the root of your workspace. By default, the workspace directory is a directory that is named go within your user home directory (~/go for Linux and MacOS, %USERPROFILE%/go for Windows). GOPATH stores your code base and all the files that are necessary for your development. You can use another directory as your workspace by configuring GOPATH for different scopes. GOPATH is the root of your workspace and contains the following folders:

src/: location of Go source code (for example, .go, .c, .g, .s).

pkg/: location of compiled package code (for example, .a).

bin/: location of compiled executable programs built by Go.

To change GOPATH for GoLand, see here.

huangapple
  • 本文由 发表于 2017年6月12日 22:51:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/44502449.html
匿名

发表评论

匿名网友

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

确定