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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:40:34  来源:igfitidea点击:

GOPATH value setting

windowsgo

提问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

  • GOROOTmust reference the folder where you installed GO
  • GOPATHmust 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/etcdshould:

Ago get github.com/coreos/etcd应该:

  • 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)
  • 下载%GOPATH%/src/github.com/coreos/etcdsrc是为您创建的)中的源
  • 编译它%GOPATH%/pkg/windows_amd64pkg/是为您创建的,windows_amd64反映了您的 Windows 架构)
  • with go install, 安装在%GOPATH%/bin(bin/也是为你创建的)

Note: with Go 1.8+ (Q2 2017), GOPATHmight 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: GOPATHis 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。所以步骤是:

  1. Download and install Godistribution(the GOROOTvariable was set automatically)
  2. Create new folder wherever you like for your workspace, create there 3 directories: bin, srcand pkg
  3. 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
  4. When you're done, RESTARTyour cmdor Bash(that's important) and you have your GOPATHset. To be sure run go envand you will see your value.
  1. 下载并安装Go发行版(GOROOT变量是自动设置的)
  2. 在您喜欢的任何工作区创建新文件夹,在那里创建 3 个目录:bin,srcpkg
  3. 然后进入控制面板->所有控制面板项->系统->Advansed系统设置->选项卡高级->环境变量->通过点击添加新的系统变量的新系统varaibles->变量名= GOPATH,变量值=Your:\directory\that\you\created
  4. 当你完成后,重新启动你的cmdBash这很重要),你就拥有了你的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]会做你的工作。