Mongodb – How to install earlier version of mongodb with homebrew

homebrewmongodb

I'm on osx6.8 and need to install an earlier version of Mongodb, how do I install an earlier version with HomeBrew?

The below didn't work 🙁

dream-2:app2 star$ brew install mongodb-2.6.10
Error: No available formula for mongodb-2.6.10 
Searching formulae...
Searching taps...
dream-2:app2 star$ 

Edit:
I'm getting a message to explain how this post is unique compared to another one, well, the answer to the other question is super long and complex and it's specific to postgresql and doesn't really answer my question.

Best Solution

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/brew

brew install mongodb-community

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

brew search mongo

brew 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 manually

killall 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 --version

brew 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-community

brew unlink mongodb-community@3.2

brew link mongodb-community                                 #*#

brew services start mongodb/brew/mongodb-community          #*#

And restart again.