Tuesday, August 09, 2022

[Solved] Error: No such keg: /usr/local/Cellar/gcc

If you are facing issues with Homebrew while installing or updating the GCC package (or any other module), follow this guide.

The error occurred for me recently during my periodic homebrew updates on my MacBook Pro.

devharsh@Devharshs-MacBook-Pro ~ % brew update && brew upgrade && brew cleanup                                                         

Already up-to-date.

Warning: Skipping gcc: most recent version 12.1.0 not installed

For some reason, I had a warning flashing up for GCC. So I tried to install the missing version.

devharsh@Devharshs-MacBook-Pro ~ % brew install -f gcc@12

Error: gcc 12.1.0_1 is already installed

To install 12.1.0, first run:

  brew unlink gcc

Which unsurprisingly did not work, so I tried unlinking it. 

devharsh@Devharshs-MacBook-Pro ~ % brew unlink gcc

Error: No such keg: /usr/local/Cellar/gcc

And this failed too, hence this post! After some troubleshooting, I could fix the issue.

First, I did unlink for GCC v12.

devharsh@Devharshs-MacBook-Pro ~ % brew unlink gcc@12

Unlinking /usr/local/Cellar/gcc@12/12.1.0_1... 665 symlinks removed.

This worked successfully, after which I did a reinstallation.

devharsh@Devharshs-MacBook-Pro ~ % brew install -f gcc   

==> Downloading https://ghcr.io/v2/homebrew/core/gcc/manifests/12.1.0

Already downloaded: /Users/devharsh/Library/Caches/Homebrew/downloads/30be1d1b4338e63c6393a6c65a6baaa374b8ad16b0d72df58bcda25fa0b72cd4--gcc-12.1.0.bottle_manifest.json

==> Downloading https://ghcr.io/v2/homebrew/core/gcc/blobs/sha256:ef8d827aef3df5e5017f019c2d0ae5e3371306305ff2b74c7a1c218ca72a7ab6

Already downloaded: /Users/devharsh/Library/Caches/Homebrew/downloads/45d3f50e0ee23935e38f181b78ea620c00da2d7a4169d5a50f906f3821b3396d--gcc--12.1.0.monterey.bottle.tar.gz

==> Pouring gcc--12.1.0.monterey.bottle.tar.gz

🍺  /usr/local/Cellar/gcc/12.1.0: 1,566 files, 299.6MB

==> Running `brew cleanup gcc`...

Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.

Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

So far, I could successfully unlinked and installed the latest GCC version. Then I did a homebrew update to check if I got rid of the warning, and it worked! 🥳

devharsh@Devharshs-MacBook-Pro ~ % brew update && brew upgrade && brew cleanup

Already up-to-date.

If nothing works for you, then as a last resort, you may want to reinstall Homebrew altogether if you are willing to lose all your installed modules.

Check your ruby path and note it down.

devharsh@Devharshs-MacBook-Pro ~ % which ruby


Execute the following command, and change the ruby path if it is different for your system.

devharsh@Devharshs-MacBook-Pro ~ % /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

Warning: The Ruby Homebrew uninstaller is now deprecated and has been rewritten in

Bash. Please migrate to the following command:

  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

Warning: This script will remove:





/usr/local/bin/brew -> /usr/local/bin/brew

Are you sure you want to uninstall Homebrew? This will remove your installed packages! [y/N] N

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.