英文:
GOPATH value setting
问题
我正在安装go,使用的是go1.3.1.windows-amd64.msi安装包。安装完成后,GOROOT是默认设置的,我在PATH中找到了D:\Programs\Go\bin路径。然后我创建了一个GOPATH环境变量。但是在使用"go get"命令时,出现了错误:
package github.com/coreos/etcd: 无法下载,$GOPATH不能设置为$GOROOT。更多详情请参考:go help gopath
操作系统:Windows 7
GOPATH会与GOROOT冲突吗?
我该如何设置这两个路径值?
英文:
I'm install the go with the go1.3.1.windows-amd64.msi, after installation GOROOT is default setting, I found the
D:\Programs\Go\bin in the PATH,then I create a GOPATH environment variant,
when using the 'go get' command, error occurs:
package github.com/coreos/etcd: cannot download, $GOPATH must not be set to $GOROOT. For more details see: go help gopath
OS: windows 7
GOPATH will conflict with GOROOT?
How can I set these two PATH values?
答案1
得分: 32
GOROOT必须指向你安装 Go 的文件夹。GOPATH必须指向一个空文件夹,它将成为你的工作空间(用于存放项目的 src/pkg/bin 文件夹)。
将这两个变量添加到你的用户环境变量中。
执行 go get github.com/coreos/etcd 应该会:
- 在
%GOPATH%/src/github.com/coreos/etcd下下载源代码(src文件夹会自动创建) - 在
%GOPATH%/pkg/windows_amd64下编译代码(pkg/文件夹会自动创建,windows_amd64反映了你的 Windows 架构) - 使用
go install命令将代码安装到%GOPATH%/bin中(bin/文件夹也会自动创建)
注意:从 Go 1.8+(2017 年第二季度)开始,默认情况下可能会为你设置 GOPATH(在 Windows 上为 %USERPROFILE%/go,在 Linux 上为 $HOME/go):参见 issue 17262。
更新于 2018 年,三年后:随着 Go 1.11 模块 的推出,GOPATH 正在逐渐过时:
mkdir newProject
cd newProject
set GO111MODULE=on
go mod init myproject
英文:
GOROOTmust reference the folder where you installed GOGOPATHmust reference an empty folder which will be your workspace (src/pkg/bin for your projects)
Add those two variables in your user environment variables.
A go get github.com/coreos/etcd should:
- download the sources in
%GOPATH%/src/github.com/coreos/etcd(srcis created for you) - compile it in
%GOPATH%/pkg/windows_amd64(pkg/is created for you,windows_amd64reflects your windows architecture) - with
go install, install it in%GOPATH%/bin(bin/is also created for you)
Note: with Go 1.8+ (Q2 2017), GOPATH might be set for you by default to (on Windows) %USERPROFILE%/go.
On Linux, it would be $HOME/go: see issue 17262.
Update 2018, three years later: GOPATH is becoming obsolete with Go 1.11 modules:
mkdir newProject
cd newProject
set GO111MODULE=on
go mod init myproject
答案2
得分: 5
我遇到了同样的问题。然而,我按照教程中所说的设置了一切,但忘记重新启动cmd。所以步骤如下:
- 下载并安装
Go发行版(GOROOT变量会自动设置) - 在任意位置创建一个新文件夹作为你的工作空间,在其中创建3个目录:
bin、src和pkg - 然后进入 控制面板
->所有控制面板项->系统->高级系统设置->高级 选项卡->环境变量->通过点击 新建 在 系统变量 中添加新的系统变量,变量名为GOPATH,变量值为你创建的目录路径 - 完成后,重启 你的
cmd或Bash(这很重要),然后你的GOPATH就设置好了。为了确认,运行go env命令,你将看到你的值。
英文:
I faced with the same problem. However i set everything as it was said in the tutorial but forgot to restart cmd. So the steps were:
- Download and install
Godistribution(theGOROOTvariable was set automatically) - Create new folder wherever you like for your workspace, create there 3 directories:
bin,srcandpkg - Then go to Control Panel
->All Control Panel Items->System->Advansed System Settings->tab Advanced->Environment Variables->add new system variable by clicking New on System varaibles->Variable name =GOPATH, Variable value =Your:\directory\that\you\created - When you're done, RESTART your
cmdorBash(that's important) and you have yourGOPATHset. To be sure rungo envand you will see your value.
答案3
得分: 1
你不应该设置$GOROOT。
输入export GOROOT=""来解决你的问题。
英文:
You should not set $GOROOT.
Type export GOROOT="" to fix your problem.
答案4
得分: 0
只需要执行 set GOPATH=[路径] 就可以完成你的工作。
英文:
Just set GOPATH=[path] would do your work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论