Homebrew says I got the latest version of Emacs installed, but the emacs command indicates it's still the old version

I updated my emacs version using Homebrew. If I now execute

brew upgrade emacs

the following message appears:

emacs 27.2 already installed

However, when I execute

emacs --version

the following message appears:

GNU Emacs 26.2

Running

which emacs

returns

/usr/local/bin/emacs

Running

ls -l /usr/local/bin/emacs $(type -p emacs)

returns

ls: emacs: No such file or directory
ls: is: No such file or directory
lrwxr-xr-x  1 evanaad  admin  44 Jul 23  2019 /usr/local/bin/emacs -> /Applications/Emacs.app/Contents/MacOS/Emacs
lrwxr-xr-x  1 evanaad  admin  44 Jul 23  2019 /usr/local/bin/emacs -> /Applications/Emacs.app/Contents/MacOS/Emacs

As per nohillside's suggestion, I've run brew uninstall emacs, removed Applications/Emacs.app, and then run brew install emacs. Here is the output of this run:

Error: 
  homebrew-core is a shallow clone.
  homebrew-cask is a shallow clone.
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
These commands may take a few minutes to run due to the large size of the repositories.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
Warning: Treating emacs as a formula. For the cask, use homebrew/cask/emacs
==> Downloading https://homebrew.bintray.com/bottles/emacs-27.2.catalina.bottle.
Already downloaded: /Users/evanaad/Library/Caches/Homebrew/downloads/49fb14649e985625a9c3e178d1c9a853ab9f3c57d538229f4e1a0188f5a6b884--emacs-27.2.catalina.bottle.tar.gz
==> Pouring emacs-27.2.catalina.bottle.tar.gz
==> emacs cask is installed, skipping link.
==> Caveats
To have launchd start emacs now and restart at login:
  brew services start emacs
Or, if you don't want/need a background service you can just run:
  emacs
==> Summary
🍺  /usr/local/Cellar/emacs/27.2: 4,012 files, 104.3MB
==> `brew cleanup` has not been run in 30 days, running now...
Error: Permission denied @ apply2files - /usr/local/share/ghostscript/9.19/Resource/Font/wasy10.p

If I now execute emacs --version I get the following message:

zsh: command not found: emacs

Per nohillside's suggestion, I've uninstalled both emacs and homebrew/cask/emacs. If I now run brew doctor, I get the following output:

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: The following directories do not exist:
/usr/local/Frameworks
/usr/local/sbin

You should create these directories and change their ownership to your user.
  sudo mkdir -p /usr/local/Frameworks /usr/local/sbin
  sudo chown -R $(whoami) /usr/local/Frameworks /usr/local/sbin

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  gdbm
  python
  libunistring
  xz
  unbound

Warning: An outdated version (2.10.1) of Git was detected in your PATH.
Git 2.14.3 or newer is required for Homebrew.
Please upgrade:
  brew install git

Warning: Xcode alone is not sufficient on Catalina.
Install the Command Line Tools:
  xcode-select --install


Warning: Broken symlinks were found. Remove them with `brew cleanup`:
  /usr/local/share/ghostscript/9.19/Resource/Font/wasy10.pfb
  /usr/local/share/ghostscript/9.19/Resource/Font/wasy5.pfb
  /usr/local/share/ghostscript/9.19/Resource/Font/wasy6.pfb
  /usr/local/share/ghostscript/9.19/Resource/Font/wasy7.pfb
  /usr/local/share/ghostscript/9.19/Resource/Font/wasy8.pfb
  /usr/local/share/ghostscript/9.19/Resource/Font/wasy9.pfb
  /usr/local/share/ghostscript/9.19/Resource/Font/wasyb10.pfb
  /usr/local/share/ghostscript/9.21/Resource/Font/wasy10.pfb
  /usr/local/share/ghostscript/9.21/Resource/Font/wasy5.pfb
  /usr/local/share/ghostscript/9.21/Resource/Font/wasy6.pfb
  /usr/local/share/ghostscript/9.21/Resource/Font/wasy7.pfb
  /usr/local/share/ghostscript/9.21/Resource/Font/wasy8.pfb
  /usr/local/share/ghostscript/9.21/Resource/Font/wasy9.pfb
  /usr/local/share/ghostscript/9.21/Resource/Font/wasyb10.pfb
  /usr/local/share/ghostscript/9.23/Resource/Font/wasy10.pfb
  /usr/local/share/ghostscript/9.23/Resource/Font/wasy5.pfb
  /usr/local/share/ghostscript/9.23/Resource/Font/wasy6.pfb
  /usr/local/share/ghostscript/9.23/Resource/Font/wasy7.pfb
  /usr/local/share/ghostscript/9.23/Resource/Font/wasy8.pfb
  /usr/local/share/ghostscript/9.23/Resource/Font/wasy9.pfb
  /usr/local/share/ghostscript/9.23/Resource/Font/wasyb10.pfb
  /usr/local/share/man/man1/brew-cask.1
  /usr/local/share/zsh/site-functions/_brew_cask

How can I get the emacs command to point to the new version?

P.S. There's a similar post on this forum, but the answer to it isn't relevant to me.


You have both the "normal" emacs and the cask version installed via Homebrew, that's why you won't get the new install linked into /usr/local/bin.

==> Pouring emacs-27.2.catalina.bottle.tar.gz
==> emacs cask is installed, skipping link.

To cleanup

  • uninstall both versions
    brew uninstall emacs
    brew uninstall homebrew/cask/emacs
    
  • run brew doctor and resolve any relevant issues
  • install one version only