Mac下的环境如下:
~$
~$
~$ echo $0
-bash
~$
~$
~$
~$
~$
~$ cat /etc/paths.d/go
/usr/local/go/bin
~$
~$ cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Users/MYUSER/go/bin
~$
~$
~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/MYUSER/go/bin:/usr/local/go/bin
~$
~$ uname -a
Darwin XYXYXYXXYX 19.6.0 Darwin Kernel Version 19.6.0: Mon Apr 12 20:57:45 PDT 2021; root:xnu-6153.141.28.1~1/RELEASE_X86_64 x86_64
~$
~$ which go
/usr/local/go/bin/go
~$
~$
~$
~$ go version
-bash: /usr/local/bin/go: No such file or directory
~$
~$
~$
~$ /usr/local/go/bin/go version
go version go1.16.4 darwin/amd64
~$
~$
我 在安装新版本 go v1.16 之前执行了安装rm -rf /usr/local/go
二进制文件的操作rm /usr/local/bin/go
go
/usr/local/go/bin
如何让go version
命令生效?
答案1
在您在问题中发布的代码片段中说:
~$ which go
/usr/local/go/bin/go
which
表示 go 二进制文件驻留在 /usr/local/go/bin 目录中(另请参阅为什么不用“哪个”呢?那该用什么呢?)但 Bash 尝试从 /usr/local/bin 目录运行:
~$ go version
-bash: /usr/local/bin/go: No such file or directory
这可能是go
二进制文件在您移动或删除之前所在的位置。在这种情况下,运行hash -r
可能会解决问题,来自help hash
:
-r 忘记所有记住的位置