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,466
  • 10
  • 29
  • 46

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

Arkadiusz Drabczyk
  • 25,049
  • 5
  • 53
  • 68
  • yes `go` binary use to reside in `/usr/local/bin`, but I removed before installing new version of go binary that got installed in new location: `/usr/local/go/bin` – overexchange Jun 03 '21 at 18:08
  • 2
    @overexchange Good! If this solves your issue, please consider [accepting the answer](https://unix.stackexchange.com/help/someone-answers). Accepting an answer marks the issue as resolved. – Kusalananda Jun 03 '21 at 20:09