Zsh: Command Not found : mongo After trying to install mongodb 4.2 using brew
Asked Answered
C

5

6

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
Casablanca answered 25/2, 2021 at 20:6 Comment(0)
C
3

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

Casablanca answered 26/2, 2021 at 4:12 Comment(0)
I
7

brew install mongodb-community-shell

Fixed the problem for me.

Ingrain answered 29/4, 2022 at 6:29 Comment(0)
C
3

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

Casablanca answered 26/2, 2021 at 4:12 Comment(0)
D
3

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

Doss answered 5/1, 2022 at 2:23 Comment(0)
C
1

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.
Camelliacamelopard answered 16/7, 2021 at 10:32 Comment(0)
V
0

In addition to @ramesh-babu-t-b 's answer, https://mcmap.net/q/1636953/-zsh-command-not-found-mongo-after-trying-to-install-mongodb-4-2-using-brew, the issue could also be that your MongoDB installation did add mongod to your path, but the installation happened within the current shell session, and so your shell doesn't have the updates to the PATH variable yet.

In this case, only his last step is still necessary - Open a new console window and retry the mongod command.

Vergne answered 20/10, 2022 at 20:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.