MongoDB installed via Homebrew not working

血红的双手。 提交于 2019-12-07 11:08:53

问题


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?


回答1:


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 mongod




回答2:


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!




回答3:


Works perfectly

  1. brew update
  2. brew tap mongodb/brew
  3. brew install mongodb-community@4.2

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




回答4:


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/



来源:https://stackoverflow.com/questions/11707938/mongodb-installed-via-homebrew-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!