我按照文档中的说明下载并安装了tar.gz文件:https://golang.org/doc/install
编辑我的.profile以包含这些行
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin第一行来自文档,第二行和第三行在Learn Go by O‘’Reilly一书中。
我的书让我为负载测试网站安装hey库。这是在安装Go这一节之后。
(base) n@u-IdeaPad-3-15IIL05: hey https://www.golang.org
Command 'hey' not found, but can be installed with:
sudo snap install hey # version 0.1.2, or
sudo snap install hey-mail # version 1.2.0
sudo apt install hey # version 0.1.2-2
See 'snap info <snapname>' for additional versions.
(base) n@u-IdeaPad-3-15IIL05:/media/n/NTFSUbuWin/Projects/Golang$ source $HOME/.profile(base) n@u-IdeaPad-3-15IIL05:/media/n/NTFSUbuWin/Projects/Golang$ hey https://www.golang.org
Summary:
Total: 1.5133 secs
Slowest: 0.6518 secs
Fastest: 0.1353 secs
Average: 0.3005 secs
Requests/sec: 132.1624
Response time histogram:
0.135 [1] |■
0.187 [61] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.239 [21] |■■■■■■■■■■■■■■
0.290 [40] |■■■■■■■■■■■■■■■■■■■■■■■■■■
0.342 [23] |■■■■■■■■■■■■■■■
0.394 [11] |■■■■■■■
0.445 [7] |■■■■■
0.497 [7] |■■■■■
0.548 [1] |■
0.600 [5] |■■■
0.652 [23] |■■■■■■■■■■■■■■■
Latency distribution:
10% in 0.1462 secs
25% in 0.1637 secs
50% in 0.2594 secs
75% in 0.3852 secs
90% in 0.6205 secs
95% in 0.6376 secs
99% in 0.6415 secs
Details (average, fastest, slowest):
DNS+dialup: 0.0134 secs, 0.1353 secs, 0.6518 secs
DNS-lookup: 0.0003 secs, 0.0000 secs, 0.0043 secs
req write: 0.0000 secs, 0.0000 secs, 0.0006 secs
resp wait: 0.1255 secs, 0.0650 secs, 0.3958 secs
resp read: 0.0031 secs, 0.0002 secs, 0.0213 secs
Status code distribution:
[200] 200 responses所以,在我从项目目录执行source $HOME/.profile之后,它就可以工作了,尽管我已经在一个不同的终端实例中运行了这个命令,我认为是全局的。
有什么问题吗?
发布于 2021-07-12 08:43:53
归根结底,~/.profile是在登录时获取的,而~/.bashrc是在您打开新终端时获取的。因此,如果您将go环境变量添加到~/.profile中,则直到您注销并再次登录时,才会获取这些变量。
golang文档建议使用~/.profile,因为它是环境变量的推荐位置。
还请注意,~/.bashrc和~/.profile都不是系统范围的。其他用户没有访问权限。可以在/etc/profile中设置系统范围的环境变量。
请参考这篇关于differences between .bashrc and .profile的精彩解释,了解更多细节。
发布于 2021-07-12 08:16:13
与我在文档中读到的关于将导出写到.profile以使其在系统范围内的内容相反,有一条注释,直到作者删除了它,它说写到我使用的任何shell。因此,在Ubuntu20.04上,我将我的导出写入.bashrc。
https://stackoverflow.com/questions/68340611
复制相似问题