user3231931
user3231931

Reputation: 331

GOPATH value setting

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?

Upvotes: 15

Views: 46208

Answers (4)

Barath
Barath

Reputation: 27

Just set GOPATH=[path] would do your work.

Upvotes: 0

VonC
VonC

Reputation: 1324128

  • GOROOT must reference the folder where you installed GO
  • GOPATH must 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 (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)

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

Upvotes: 32

julien bouteloup
julien bouteloup

Reputation: 3092

You should not set $GOROOT.

Type export GOROOT="" to fix your problem.

Upvotes: 1

vishes_shell
vishes_shell

Reputation: 23484

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:

  1. Download and install Go distribution(the GOROOT variable was set automatically)
  2. Create new folder wherever you like for your workspace, create there 3 directories: bin, src and 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 New on System varaibles -> Variable name = GOPATH, Variable value = Your:\directory\that\you\created
  4. When you're done, RESTART your cmd or Bash(that's important) and you have your GOPATH set. To be sure run go env and you will see your value.

Upvotes: 5

Related Questions