1

Below is the environment in 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
~$
~$

I performed rm -rf /usr/local/go , rm /usr/local/bin/go before installing new version go v1.16 that installs go binary in /usr/local/go/bin

How to make go version command work?

overexchange
  • 1,536

1 Answers1

7

In the snippet you posted in your question it says:

~$ which go
/usr/local/go/bin/go

which indicates that go binary resides in /usr/local/go/bin directory (also see Why not use “which”? What to use then?) but Bash tries to run from it /usr/local/bin directory:

~$ go version
-bash: /usr/local/bin/go: No such file or directory

This is probably where go binary used to reside before you moved or removed it. In situations like this running hash -r may fix the problem, from help hash:

-r forget all remembered locations