Reputation: 33678
I unzipped the Go distribution into d:\dev\go
, added d:\dev\go\bin
to my path, created a file d:\projects\hello\hello.go
and set GOPATH to d:\projects\hello
. Running go build hello.go
tells me:
go: cannot find GOROOT directory: c:\go
Now several different places strongly urge me not to set GOROOT, setting GOPATH should be everything that is needed.
Should I go against this recommendation or is there something I am missing?
Upvotes: 5
Views: 20443
Reputation: 11
I got this error when compiling and when getting the compiler version, I solved the problem by deleting the system variable GOROOT and reassigning it. was c:\Go; became c:\Go =)
Upvotes: 1
Reputation: 5808
Once Go lang is installed, GOROOT is the root directory of the installation.
When I exploded Go Lang binary in Windows C:\ directory, my GOROOT should be C:\go. If Installed with Windows installer, it may be C:\Program Files\go (or C:\Program Files (x86)\go, for 64-bit packages)
GOROOT = C:\go
Upvotes: 1
Reputation: 4615
Maybe the cache problem.
For me, I reopen the MinGW (I installed go in msys2 by pacman), and it worked.
Upvotes: -1
Reputation: 7878
From Dave Cheney's You don’t need to set GOROOT, really article:
There are only two cases that where you may have to set a
$GOROOT
environment. These are both described in the installation page on the golang.org website. For completeness I will recap them here
- You are a Linux, FreeBSD or OS X user using the the zip or tarball binary downloads from the golang.org website. These binaries have a
$GOROOT
value of/usr/local/go
and recommend you unpack them into that location. If you choose not to do this, then you must set$GOROOT
to the location you chose.- You are a Windows user using the zip binary download from the golang.org website. These binaries have a
$GOROOT
value ofC:\Go
. If you place Go somewhere else on your system then you must set$GOROOT
to the location you chose.
(The rest of the article is a good read if you want to learn the history that has caused confusion over GOROOT
, the summary is it's due to outdated instructions mostly from pre-Go1.)
So if you use a pre-built Go binary, and you want to put it somewhere other than where it "wants", then you need GOROOT
. Otherwise (i.e. if you build Go from source, or if you put the binary distribution in the default location) you don't need or want to set GOROOT
(the above article gives some reasons why not).
If you're unsure, the easiest way to get it "correct" is to first not set anything other GOPATH
. Then run go env
and see what it says; if that shows reasonable entries for GOROOT
and GOPATH
then you're done; only set variables to override that if it's wrong.
Upvotes: 10
Reputation: 5702
I set GOROOT to point to the content of that dir:
AUTHORS PATENTS api favicon.ico misc src
CONTRIBUTORS README bin include pkg test
LICENSE VERSION doc lib robots.txt
That's the dir which containts src, bin, doc, lib, etc...
Upvotes: 0