【问题标题】:Why is $GOPATH often set in ~/.bashrc and ~/.bash_profile instead of ~/.profile?为什么 $GOPATH 经常设置在 ~/.bashrc 和 ~/.bash_profile 而不是 ~/.profile?
【发布时间】:2018-04-24 11:06:12
【问题描述】:

在 Go 在 Github 上的 wiki 页面中,它被告知设置在 ~/.bash_profile 中:

https://github.com/golang/go/wiki/Setting-GOPATH

在这个 StackOverflow 问题中,大多数投票最多的答案建议设置在 ~/.bashrc 文件中:

how do I SET the GOPATH environment variable on Ubuntu? What file must I edit?

我已经读到 ~/.profile 可能是设置环境变量的最佳方式。是否有原因 ~/.profile 不用于设置 $GOPATH 还是只是偏好问题?

【问题讨论】:

  • 建议.bashrc的答案不正确,不知道原因的人太多了。

标签: go environment-variables gopath


【解决方案1】:

使用你的 shell 配置文件

如果你已经有一个.bash_profile 文件,你可以使用它,否则使用.profile。您也可以从.bash_profile 获取.profile,并将您需要的任何内容添加到.profile;见this answer for more info

为什么不.bashrc

如果将环境变量添加到.bashrc,您可以体验duplicate PATH entries 之类的东西,但这也意味着这些变量仅在从shell 启动的进程中可用。对于GOPATH,这通常不是问题,但it is PATH-like,因此您应该坚持使用shell 配置文件以避免任何潜在问题。

【讨论】:

    猜你喜欢
    • 2013-10-15
    • 1970-01-01
    • 2010-09-29
    • 2014-09-21
    • 2016-10-04
    • 1970-01-01
    相关资源
    最近更新 更多