go: 找不到 GOROOT 目录: C:\Go; C:\Go\bin

huangapple go评论94阅读模式
英文:

go: cannot find GOROOT directory: C:\Go; C:\Go\bin

问题

标题如下,我刚刚在我的笔记本电脑上安装了Go包。
操作系统:Windows 7企业版SP1(64位)
安装路径:C:\go

我已经设置了“环境变量”:

GOROOT
值 = C:\GO;C:GO\bin

我创建了hello.go文件并将其保存在C:\go中。

当我在CMD中运行"go run hello.go"时,在C:\目录下收到以下错误消息:

go:无法找到GOROOT目录:C:\Go; C:\Go\bin
英文:

As title, I just install Go package in my laptop.
OS:Windows 7 Enterpreise SP1 (64bit)
Install path: C:\go

I've set "Environment Variables":

GOROOT 
Value = C:\GO;C:GO\bin

I made hello.go file and save it in C:\go

When I run "go run hello.go" in CMD in C:\, get error message as below:

go:cannot find cannot find GOROOT directory: C:\Go; C:\Go\bin

答案1

得分: 3

如果你将Go安装在d:/programs/go目录下,应将GOROOT设置为该路径。如果你希望将GOPATH设置在d:/workspace/gopath目录下,应将其设置为该路径。此外,最好将d:\programs\go\bin添加到PATH环境变量中。

看起来Go只接受斜杠(/)而不是反斜杠(\)。但是当然,对于PATH环境变量来说,应该使用反斜杠(\)。

英文:

GOROOT should be set to d:/programs/go if you installed it there.
GOPATH should be set to d:/workspace/gopath if you want it there.
Also, d:\programs\go\bin should preferably be added to PATH.

It seems like Go only accepts slash (/) and not backslash (\). But of course, for PATH, it should be backslash (\).

答案2

得分: 2

Golang文章《如何编写Go代码》提到:

GOPATH环境变量指定了工作空间的位置。在开发Go代码时,这可能是你唯一需要设置的环境变量。
请注意,这个路径不能与你的Go安装路径相同。

(Go安装路径由GOROOT引用)

< 要开始,请创建一个工作空间目录并相应地设置GOPATH
你可以将工作空间放在任何你喜欢的位置,但在本文档中我们将使用$HOME/go

mkdir %USERPROFILE%\go
set GOPATH=%USERPROFILE%\go

> 为了方便起见,将工作空间的bin子目录添加到你的PATH中:

set PATH=%PATH%;%GOPATH%\bin
英文:

The Golang article "How to Write Go Code" does mention:

The GOPATH environment variable specifies the location of your workspace. It is likely the only environment variable you'll need to set when developing Go code.
Note that this must not be the same path as your Go installation.

(and go installation is reference by GOROOT)

< To get started, create a workspace directory and set GOPATH accordingly.
Your workspace can be located wherever you like, but we'll use $HOME/go in this document.

mkdir %USERPROFILE%\go
set GOPATH=%USERPROFILE%\go

> For convenience, add the workspace's bin subdirectory to your PATH:

set PATH=%PATH%;%GOPATH%\bin

答案3

得分: 1

请不要设置 GOROOT。请查看 http://golang.org/doc/articles/go_command.html

英文:

Do not set GOROOT. Have a look at http://golang.org/doc/articles/go_command.html

答案4

得分: -2

你需要按照以下步骤添加(编辑系统环境变量)GOPATHGOROOT(适用于Windows 10),然后重新启动系统。

go: 找不到 GOROOT 目录: C:\Go; C:\Go\bin

英文:

you will need to add (Edit the system environment variables) GOPATH & GOROOT as below. (Windows 10) And then restart the system

go: 找不到 GOROOT 目录: C:\Go; C:\Go\bin

huangapple
  • 本文由 发表于 2014年2月20日 13:52:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/21899332.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定