'Zsh: Command Not found : mongo After trying to install mongodb 4.2 using brew

I have tried the following steps to install and setup mongodb in my mac from here https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/ but I got the following error when running the final "mongo" command in my terminal:

Error Message - Zsh: Command Not found : mongo

This error msg occurred after trying to install mongodb 4.2 using brew

sudo chown -R $(whoami) $(brew --prefix)/*

then

brew tap mongodb/brew

then

brew install [email protected]

and

brew services start [email protected]

or

mongod --config /usr/local/etc/mongod.conf

then

ps aux | grep -v grep | grep mongod

and

mongo

running brew services start [email protected] returns:

Successfully started `[email protected]` (label: [email protected])

running ps aux | grep -v grep | grep mongod returns:

9081   0.2  0.5  5528024  41856   ??  S     3:01pm   0:01.48 /usr/local/opt/[email protected]/bin/mongod --config /usr/local/etc/mongod.conf

7613   0.0  0.1  4298832   5600 s000  T     2:47pm   0:00.08 vim /usr/local/etc/mongod.conf

running mongod --config /usr/local/etc/mongod.conf returns:

zsh: command not found: mongod

There are also no mongo files in my /usr/local/bin directory after using these commands

I created a data/db folder in my /usr/local/bin directory using the following commands:

sudo mkdir -p  /usr/local/bin/data/db   
sudo chown -R `id -un`  /usr/local/bin/data/db      

Running "brew update" returns:

brew update                                                                                                                                                    
Updated 1 tap (homebrew/cask).
==> Updated Casks
brave-browser


Solution 1:[1]

Solved it by manually installing the mongodb community files and db tools using the website instead. Then copying them into /usr/local/bin. Then ignoring the app permissions whenever calling mongo or related commands in the terminal through System Preferences > Security & Privacy > General.

After googling I found out that mongoimport and the other features have to be installed separately: https://www.mongodb.com/try/download/database-tools

Followed by copying those bin files after extracting them into the same /usr/local/bin directory

Not sure why its' not working through homebrew though

Solution 2:[2]

This worked for me, I was having same issue on [email protected]

 brew reinstall [email protected]  

On terminal something like this will appear during reinstallation.

enter image description here

copy highlighted path with echo

 echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

Now open another terminal and start mongodb services

brew services restart mongodb/brew/[email protected]

write mongo on terminal and here we fly

enter image description here

Solution 3:[3]

If you installed the mongodb via Homebrew. Need to add the mongo path in your bash_profile.

  • Edit the bash_profile vi ~/.bash_profile
  • Add the below line in EOF export PATH=$PATH:/usr/local/opt/[email protected]/bin
  • After the edit bash_profile. Close all terminals and open them again. mongo command start works.

Solution 4:[4]

brew install mongodb-community-shell

Fixed the problem for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DreamVision2017
Solution 2 saud00
Solution 3 Ramesh Babu T B
Solution 4 Kshateesh