MongoDB installed via Homebrew not working

大兔子大兔子 提交于 2019-12-05 12:42:26
William Z

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

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!

Den

Works perfectly

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

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/

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