在Github的Go的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,还是只是偏好?
答案 0 :(得分:1)
如果您已有.bash_profile
个文件,则可以使用它,否则请使用.profile
。您也可以从.profile
中提取.bash_profile
,然后将所需内容添加到.profile
;见this answer for more info。
.bashrc
?如果将环境变量添加到.bashrc
,您可以体验duplicate PATH
entries之类的内容,但这也意味着这些变量仅在从shell启动的进程中可用。对于GOPATH
,这通常不是问题,而是it is PATH
-like,因此您应该坚持使用shell配置文件以避免任何潜在问题。