mrgloom
mrgloom

Reputation: 21642

Uninstall protobuf competely

Seems brew fails to uninstall protobuf completely:

brew uninstall protobuf --force
brew uninstall [email protected] --force

brew info protobuf
protobuf: stable 3.6.1 (bottled), HEAD
Protocol buffers (Google's data interchange format)
https://github.com/protocolbuffers/protobuf/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/protobuf.rb
==> Dependencies
Build: autoconf ✘, automake ✘, libtool ✔
Recommended: python@2 ✔
Optional: python ✘
==> Options
--with-python
    Build with python support
--without-python@2
    Build without python2 support
--HEAD
    Install HEAD version
==> Caveats
Editor support and examples have been installed to:
  /usr/local/Cellar/protobuf/3.6.1/share/doc/protobuf
==> Analytics
install: 20,550 (30 days), 75,916 (90 days), 307,704 (365 days)
install_on_request: 10,362 (30 days), 36,197 (90 days), 141,839 (365 days)
build_error: 0 (30 days)

brew uninstall protobuf
Error: No such keg: /usr/local/Cellar/protobuf

protoc
-bash: /usr/local/opt/[email protected]/bin/protoc: No such file or directory

What is the proper way to uninstall it completely?

Upvotes: 3

Views: 13363

Answers (1)

bfontaine
bfontaine

Reputation: 19861

It’s not Homebrew’s fault: it’s Bash’.

When you type protoc, Bash searches the executable in your PATH. In your case, it’s /usr/local/opt/[email protected]/bin/protoc. However, it only does that the first time: it caches its findings for the session.

You uninstalled protobuf and so Homebrew removed the /usr/local/opt/[email protected]/bin/protoc file; but you haven’t cleared Bash’ cache, so it still thinks this file exists.

The solution is to either start a new shell session or force Bash to clear its cache with hash -r.


Illustration:

$ touch /tmp/hi
$ chmod u+x /tmp/hi
$ export PATH="/tmp:$PATH"

$ which hi
/tmp/hi
$ hi  # <-- executes /tmp/hi and cache hi=/tmp/hi

$ rm /tmp/hi
$ hi  # <-- still executes /tmp/hi because of the cache
bash: /tmp/hi: No such file or directory

$ hash -r # clear the cache
$ hi
hi: command not found

Upvotes: 5

Related Questions