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条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘