1

I'm following the official instructions found here (on Mac OS Big Sur): https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

When attempting to run mongo, I receive:

zsh: command not found: mongo

I then check if MongoDB is running by running:

brew services start mongodb-community@4.4

I then receive:

Service mongodb-community@4.4 already started, use brew services restart mongodb-community@4.4 to restart

Because of this, I know MongoDB is running. What gives? I followed the official instructions from MongoDB's website.

nequstion39
  • 21
  • 1
  • 1
  • 5
  • mongo vs mongod. missed the "D" – Marek H Aug 07 '21 at 18:55
  • mongod is for starting the daemon. MongoDB is already running. I am attempting to access the shell, thus mongo. Regardless, mongod has the same response: `zsh: command not found: mongod` @MarekH – nequstion39 Aug 07 '21 at 18:59
  • The binary for the shell is `mongosh` (as documented in the link you posted). Also check, if the binary folder of brew is part of the PATH variable. – dunni Aug 07 '21 at 19:05
  • On intel macs this path should work "/usr/local/bin/mongosh", "/usr/local/bin/mongod", "/usr/local/bin/mongo". Seems there were some warnings during instal which you have missed – Marek H Aug 07 '21 at 19:09
  • There is nothing mongo related in /usr/local/bin @MarekH I am on the M1 architecture if that makes a difference – nequstion39 Aug 07 '21 at 19:56
  • Reinstall and read warnings (during install). Brew also prints where binary was installed/placed – Marek H Aug 07 '21 at 22:58

5 Answers5

13

For Apple M1 Processor:

If you install mongodb through Homebrew, follow the steps below:

  1. Open up your Terminal

  2. Type brew list to check the formulae of the installed mongodb

==> Formulae 
mongodb-community@4.4   mongodb-dxxx... 

==> Casks
xxxxx
  • In my case, it is mongodb-community@4.4.
  1. In the terminal, type brew list mongodb-community@4.4 to get the directory of the mongodb installed in your machine.
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin/install_compass
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin/mongo
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin/mongod
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin/mongos
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/homebrew.mxcl.mongodb-community@4.4.plist
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/MPL-2
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/THIRD-PARTY-NOTICES
  1. Copy the bin path of your mongodb: /opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin

  2. Open up your .zshrc file with any text-editor

  3. Add this line to the file:

export PATH="/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin:${PATH}"
  1. Try mongo --version in your terminal, if you see similar output like shown below, you are good to go.
MongoDB shell version v4.4.13
Build Info: {
    "version": "4.4.13",
    "gitVersion": "df25-----------b9246",
    "modules": [],
    "allocator": "system",
    "environment": {
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}
Hanry
  • 141
  • 1
  • 5
13

I did the above procedures and it still didn't work. But use this, then it worked!

brew install mongodb-community-shell

Xinyi Zhang
  • 151
  • 1
  • 2
  • This worked for me, I had installed mongodb, it had the bin folders, but no client. Such a simple thing to overlook. Thanks. – Werner Weber Nov 28 '22 at 12:56
  • I also tried Hanry's procedures without success. Xinyi's answer here worked with and without Hanry's changes. Thank you! – gabriellend Mar 17 '23 at 21:09
2
echo 'export PATH="/usr/local/opt/mongodb-community@4.4/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
pzaenger
  • 11,381
  • 3
  • 45
  • 46
geqin
  • 21
  • 2
  • This is the best solution for using ZSH (instead of Bash) and typing `mongod --version` (not sure if the OP had a typo but I had the same problem with the correct spelling). Thanks! – a4xrbj1 May 16 '23 at 11:08
2

I solved my problem with this command running on terminal but only path I added is diffrent Steps:

  1. brew list mongodb-community@4.0. (run this first)

  2. then copied /opt/homebrew/Cellar/mongodb-community@4.0/4.0.28/bin. this path

  3. and executed:

    echo 'export PATH="/opt/homebrew/Cellar/mongodb-community@4.0/4.0.28/bin:$PATH"' >> ~/.zshrc
    source ~/.zshrc
    
  4. Then I have checked by openning .zshrc file is my path has set on not by executing - nano .zshrc command

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Rupali
  • 21
  • 2
0

I did the above procedures and it still didn't work. But I restarted my terminal using $exec bash -l and it works!

cqjun
  • 11