windows GOPATH 值设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25499670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GOPATH value setting
提问by user3231931
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:
我用go1.3.1.windows-amd64.msi安装go,安装后GOROOT是默认设置,我在PATH中找到了D:\Programs\Go\bin,然后我创建了一个GOPATH环境变量,使用时'go get' 命令,发生错误:
package github.com/coreos/etcd: cannot download, $GOPATH must not be set to $GOROOT. For more details see: go help gopath
包 github.com/coreos/etcd:无法下载,$GOPATH 不能设置为 $GOROOT。更多详情请看:go help gopath
OS: windows 7
操作系统:Windows 7
GOPATH will conflict with GOROOT?
GOPATH 会不会和 GOROOT 冲突?
How can I set these two PATH values?
如何设置这两个 PATH 值?
回答by VonC
GOROOT
must reference the folder where you installed GOGOPATH
must reference an empty folder which will be your workspace(src/pkg/bin for your projects)
GOROOT
必须引用您安装 GO 的文件夹GOPATH
必须引用一个空文件夹,该文件夹将作为您的工作区(您的项目的 src/pkg/bin)
Add those two variables in your user environment variables.
在您的用户环境变量中添加这两个变量。
A go get github.com/coreos/etcd
should:
Ago get github.com/coreos/etcd
应该:
- download the sources in
%GOPATH%/src/github.com/coreos/etcd
(src
is created for you) - compile it in
%GOPATH%/pkg/windows_amd64
(pkg/
is created for you,windows_amd64
reflects your windows architecture) - with
go install
, install it in%GOPATH%/bin
(bin/
is also created for you)
- 下载
%GOPATH%/src/github.com/coreos/etcd
(src
是为您创建的)中的源 - 编译它
%GOPATH%/pkg/windows_amd64
(pkg/
是为您创建的,windows_amd64
反映了您的 Windows 架构) - with
go install
, 安装在%GOPATH%/bin
(bin/
也是为你创建的)
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.
注意:在 Go 1.8+ (Q2 2017) 中,GOPATH
可能默认设置为 (on Windows) %USERPROFILE%/go
。
在 Linux 上,它将是$HOME/go
:参见issue 17262。
Update 2018, three years later: GOPATH
is becoming obsolete with Go 1.11 modules:
三年后的 2018 年更新:GOPATH
随着Go 1.11 模块变得过时:
mkdir newProject
cd newProject
set GO111MODULE=on
go mod init myproject
回答by vishes_shell
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:
我遇到了同样的问题。但是我按照教程中的说明设置了所有内容,但忘记重新启动cmd
。所以步骤是:
- Download and install
Go
distribution(theGOROOT
variable was set automatically) - Create new folder wherever you like for your workspace, create there 3 directories:
bin
,src
andpkg
- Then go to Control Panel
->
All Control Panel Items->
System->
Advansed System Settings->
tab Advanced->
Environment Variables->
add new system variable by clicking Newon System varaibles->
Variable name =GOPATH
, Variable value =Your:\directory\that\you\created
- When you're done, RESTARTyour
cmd
orBash
(that's important) and you have yourGOPATH
set. To be sure rungo env
and you will see your value.
- 下载并安装
Go
发行版(GOROOT
变量是自动设置的) - 在您喜欢的任何工作区创建新文件夹,在那里创建 3 个目录:
bin
,src
和pkg
- 然后进入控制面板
->
所有控制面板项->
系统->
Advansed系统设置->
选项卡高级->
环境变量->
通过点击添加新的系统变量的新的系统varaibles->
变量名=GOPATH
,变量值=Your:\directory\that\you\created
- 当你完成后,重新启动你的
cmd
或Bash
(这很重要),你就拥有了你的GOPATH
设置。确保运行go env
,你会看到你的价值。
回答by julien bouteloup
You should not set $GOROOT
.
你不应该设置$GOROOT
.
Type export GOROOT=""
to fix your problem.
键入export GOROOT=""
以解决您的问题。
回答by Barath
Just set GOPATH=[path]
would do your work.
只是set GOPATH=[path]
会做你的工作。