简体   繁体   中英

zsh: command not found: mongo

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.

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"
    }
}
echo 'export PATH="/usr/local/opt/mongodb-community@4.4/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

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

and it's done

Thanks

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

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

brew install mongodb-community-shell

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM