How to install earlier version of mongodb with homebrew? How to install earlier version of mongodb with homebrew? mongodb mongodb

How to install earlier version of mongodb with homebrew?


Note: In September 2019 mongodb was removed from homebrew core, so these instructions have been updated to use mongodb-community instead, installed from the external tap.

If your current installation is still the pre-September mongodb package then you will need to use that name when you unlink, stop, relink and start, on the lines marked with #*# below.

Another option is to simply upgrade away from the deprecated package now.

I already have the latest version of mongo installed, thanks to.

brew tap mongodb/brewbrew install mongodb-community

But I want to switch to the old version sometimes. First, install it:

brew search mongobrew install mongodb-community@3.2

Let's stop the current mongodb, if it is running:

brew services stop mongodb/brew/mongodb-community           #*## or if you had started it manuallykillall mongod

Now I want 3.2 on my PATH instead of the latest:

brew unlink mongodb-community                               #*#brew link --force mongodb-community@3.2

(Apparently it needs --force because it is keg-only.)

Now I have 3.2 on my PATH, I can start the test DB:

mongod --versionbrew services start mongodb/brew/mongodb-community# or start your own mongod from the command-line

When I am finished, I can do the reverse to switch back to the latest version:

brew services stop mongodb/brew/mongodb-communitybrew unlink mongodb-community@3.2brew link mongodb-community                                 #*#brew services start mongodb/brew/mongodb-community          #*#

And restart again.


When trying to install old versions of something with homebrew, it's usually useful to start with brew search packagename, in this case, there's a 2.6 version available under homebrew/versions/mongodb26

So, to install that version:

brew install homebrew/versions/mongodb26

Edit

This answer has certainly become very dated. Take a look at the answer below for a valid way to accomplish this in 2021.


Addition to the excellent answer of joeytwiddle :

if you don't want to link then unlink the old version of the software, you can just run it from the "cellar" (/usr/local/Cellar/), where brew installed it. Use ls /usr/local/Cellar/ to find the exact path of the executable. For example in my case, to run mongo shell:

/usr/local/Cellar/mongodb@3.6/3.6.7/bin/mongo