dongwei8440 2015-06-27 23:52 采纳率: 100%
浏览 2535
已采纳

go:找不到GOROOT目录:c:\ go

我将GO发行版解压缩到d:\dev\go,将d:\dev\go\bin添加到我的路径中,创建了一个文件d:\Projects\hello\hello.go并将GOPATH设置为d:\Projects\hello。运行Go Build hello.go后则显示:

go: cannot find GOROOT directory: c:\go

现在好几个不同的地方都在强烈敦促我不要设置 GOROOT,设置 GOPATH 才是需要的。

我应该反对这个建议吗?还是我遗漏了什么?

  • 写回答

4条回答 默认 最新

  • douyi1939 2015-06-28 15:05
    关注

    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 of C:\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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致