你是否仍然需要声明GOPATH?

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

should I still declare GOPATH?

问题

我正在阅读《学习GO》并建议将其声明为路径GOPATH="/home/user/go"

这是作者的建议:

明确定义GOPATH是一个好主意,并将$GOPATH/bin目录添加到可执行路径中。明确定义GOPATH可以清楚地指示您的Go工作区的位置,并将$GOPATH/bin添加到可执行路径中可以更轻松地运行通过go install安装的第三方工具。

当我运行go env时,1.18.1已经被声明了,所以为什么还建议在.bashrc.bash_profile中声明路径?

谢谢。

英文:
  • I WAS reading Learning GO and suggest that needs to be declared on PATH
    GOPATH="/home/user/go".

this is from author:

> it’s a good idea to explicitly define GOPATH and to put the $GOPATH/bin directory in your executable path. Explicitly defining GOPATH makes it clear where your Go workspace is located and adding $GOPATH/bin to your executable path makes it easier to run third-party tools installed via go install.

  • when I run go env 1.18.1, is already declared, so why still suggesting declaring inside your path in .bashrc or .bash_profile

thanks

答案1

得分: 2

你好!以下是翻译好的内容:

> 我是否仍然需要声明GOPATH和GOROOT?

不需要,不需要!

GOPATH默认为$HOME/go,这是可以的,而且基于GOPATH的构建方式已经过时了,已经有好几年了。现在应该使用模块(modules)。

对于Go的最终用户来说,GOROOT从来都不是一个问题。只有在你要开发Go编译器本身或者在非常不寻常的位置安装Go时才需要设置GOROOT(但最终用户不应该这样做)。

请远离任何推广GOPATH或者建议修改GOROOT的资源。

英文:

> [S]hould I still declare GOPATH, GOROOT?

No and NO!

GOPATH defaults to $HOME/go which is fine and GOPATH based builds are deprecated since several years. Use modules.

GOROOT never was a thing for the enduser of Go. You have to set if you work on the Go compiler itself or install Go in unusual location (which no enduser should do).

Keep away from any resource wich promotes GOPATH or even advises to mess with GOROOT.

huangapple
  • 本文由 发表于 2022年5月14日 16:48:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/72238666.html
匿名

发表评论

匿名网友

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

确定