I foolishly uninstalled GCC 4.9 after brew upgrade
ing to GCC 5. However I need both versions and I need to be able to switch back and forth. I thought I could just do brew switch 4.9.2
but the old version of GCC was installed to the folder Cellar/gcc49/4.9.2
instead of Cellar/gcc/4.9.2
, so Homebrew doesn't know where to find the old version.
How can I force Homebrew to install both versions in Cellar/gcc
?
That is, I have:
brew list --versions gcc
# gcc 5.1.0
brew list --versions gcc49
# gcc49 4.9.2_1
But I'd like to have:
brew list --versions gcc
# gcc 5.1.0 4.9.2_1
Best Answer
You can’t, those are different formulae, and Homebrew doesn’t allow you to install a previous version of a formula.
The workaround is to remove
gcc
, then go back in Homebrew’s history (remember that it’s a Git repository), get thegcc
formula as it was before the 5.1.0 upgrade, install it, then upgradegcc
to get the latest version.The 5.1.0
gcc
upgrade was done in Homebrew commit9cf3d4da1148c0a0d2f42c2fbe75f9a557339bab
:You need to checkout the parent commit:
Then get the
gcc
formula and save it somewhere:If you’re lazy I put this formula online here. You can now go Back to the Future:
Be sure you removed the current
gcc
:Now install the 4.9 version, either from your local copy:
Or from my online copy:
You should now have a working GCC 4.9 install. Now, upgrade to get the 5.2:
Done.