Skip to content

Instantly share code, notes, and snippets.

@initFabian
Last active July 22, 2021 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save initFabian/5215697c5159b5c75aceb2dc2b596713 to your computer and use it in GitHub Desktop.
Save initFabian/5215697c5159b5c75aceb2dc2b596713 to your computer and use it in GitHub Desktop.
Switch in-between mongo versions

Stack Overflow Question

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@4.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 4.2 on my PATH instead of the latest:

brew unlink mongodb-community                               #*#

brew link --force mongodb-community@4.2

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

Now I have 4.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@4.2

brew link mongodb-community                                 #*#

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

And restart again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment