MongoDB installed via Homebrew not working

Viewed 36590

I installed MongoDB via Homebrew (following http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/) but it's not working.

Typing mongod at shell prompt gives me:

-bash: mongod: command not found

Not sure if I need to add something for Homebrew to my PATH env var?

I can see Mongo is installed under /usr/local/Cellar/mongodb – but am assuming I don't need to add everything I install via homebrew to the path? Also, assuming I can run mongod from any directory or am I actually meant to be in install directory?

When I run brew doctor I get:

Warning: You have unlinked kegs in your Cellar 

Followed by a list of 3 items which includes MongoDB – but I'm not sure how I'm meant to link them?

6 Answers

If you are on mongodb-community@4.0. You can try to reinstall with brew reinstall mongodb-community@4.0.

Then I get the following hint:

==> Caveats
mongodb-community@4.0 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have mongodb-community@4.0 first in your PATH run:
  echo 'export PATH="/usr/local/opt/mongodb-community@4.0/bin:$PATH"' >> ~/.bash_profile

So you can just copy the echo command and restart your shell!

Copied from a different channel running these commands in the terminal updated the installation/configuration issues as described in OP

brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb-community

I faced the same problem and this solution seemed to work for me. I had previously uninstalled mongodb and reinstalled it through homebrew which gave me a bunch of problems. This solution seemed to work just fine.

brew uninstall --force mongodb
brew cleanup -s mongodb
brew cleanup --prune-prefix
brew install mongodb
Related