webgirl
webgirl

Reputation: 405

MongoDB installed via Homebrew not working

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?

Upvotes: 17

Views: 41869

Answers (6)

Amijeet Thakur
Amijeet Thakur

Reputation: 77

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

Upvotes: 1

Max Pietrzak
Max Pietrzak

Reputation: 91

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

Upvotes: 3

William Z
William Z

Reputation: 11129

You're getting this error because your 'brew' install failed to create the correct symlinks in /usr/local/bin. As a result, the shell can't find the mongo executables in your $PATH. You can fix this using the following steps:

  • Check the permissions on /usr/local/bin and make sure that you own that directory and have write permissions on it

    $ ls -ld /usr/local/bin

  • Once you've fixed that, run 'brew link' to fix the symlinks

    $ brew link mongodb

Upvotes: 10

Den
Den

Reputation: 311

Works perfectly

  1. brew update
  2. brew tap mongodb/brew
  3. brew install [email protected]

For latest version, check https://docs.mongodb.com/manual/release-notes/

Upvotes: 20

illnr
illnr

Reputation: 800

If you are on [email protected]. You can try to reinstall with brew reinstall [email protected].

Then I get the following hint:

==> Caveats
[email protected] 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 [email protected] first in your PATH run:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile

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

Upvotes: 7

Sammaye
Sammaye

Reputation: 43884

It works from the directory since the sh searches the ENV path and then the cwd for a program named mongod. I have been looking around a little and it seems that the default install of MongoDB (I am not a Mac user) does not install a rc or init script for which sh to understand it's running behaviour as stated here:

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/#using-mongodb-from-homebrew-and-macports

The packages installed with Homebrew and MacPorts contain no control scripts or interaction with the system’s process manager.

If you have configured Homebrew and MacPorts correctly, including setting your PATH, the MongoDB applications and utilities will be accessible from the system shell. Start the mongod process in a terminal (for testing or development) or using a process management tool.

So you must actually define (as you said) MongoDBs path, here is an example: https://snipt.net/sido/installing-mongodb-on-os-x/

Edit: the example is not mine. I just stole it from it's user: https://snipt.net/sido/

Upvotes: 0

Related Questions