Can't Use Mongo Command, Shows Command Not Found on Mac
I'm Using Mac Lion. I Was Using Mongodb Version 1.4. I Wanted to Upgrade to 1.8.5 and I Followed Step Wise Replacing Each Mongodb-Osx-X86_64-1.4.0 by...
I'm using Mac Lion. I was using mongodb version 1.4. I wanted to upgrade to 1.8.5 and I followed step wise replacing each mongodb-osx-x86_64-1.4.0 by mongodb-osx-x86_64-1.8.5. Everything goes smooth. I tried:
mongod
it's ok. I can access localhost:28017 but,
mongo
shows command not found
How can I fix this?
10 Answers
You need to add the path to "mongo" to your terminal shell.
export PATH=$PATH:/usr/local/mongodb/bin
Did you do the last step with paths.d? If so, try restarting your terminals.
Do you have a good reason for using 1.8.5? The current stable is 2.0.4, and it has many useful upgrades from 1.8.x
Must Read
For readers in 2021:
export PATH="$PATH:/usr/local/opt/mongodb-community@3.6/bin"
You'll have to add the location of the Mongo binary to PATH.
Follow the steps below in order to make the PATH variable permanent:
- Open Terminal and navigate to your user directory.
- Run
touch ~/.bash_profileand thenopen ~/.bash_profile. - In TextEdit, add
export PATH="<mongo-directory>/bin:$PATH"(Keep the quote marks - related to white spaces). - Save the
.bash_profilefile and Quit (Command + Q) Text Edit. - Run
source ~/.bash_profile. - Run
echo $PATHand check if the you see that the Mongo binary was added.
(*) Notice that the PATH variable is now available only for the current terminal and not to processes that were already started in the session.
In order to make it available outside the current terminal - you'll have to logout and login.
1.Go to your [mongodb installation dir]:
cd <mongodb installation dir>
2.Type ./bin/mongo to start mongo:
./bin/mongo
Note :
If above command gives error
Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and/or LC_ environment variables are set correctly.*
Run bellow command: Read More
export LC_ALL=C
How can find installation directory
find / -name "mongodb"
You can also set path
export PATH=$PATH:<mongodb installation dir>/bin
export PATH={mongodb-install-directory}/bin:$PATH
You can navigate to the mongo directory using the command line and then start MongoDB with
./mongodb
I was facing the same problem this worked for me.
you need to install mongodb shell to ge the mongo command working.
Download link
I didn't have the right mongo command line tools installed. This from Brew worked for me though.
brew install mongodb-community
In Mac:
Go into Bash Profile:
vi ~/.bash_profile
Add Path of Installation of MongoDB:
export PATH=$PATH:/usr/local/opt/mongodb-community@4.2/bin
Reload the Bash Profile:
source ~/.bash_profile
just a little recommandation, if your path has a space just wrap the whole path with quote or doublequote example : C:\Program Files\MongoDB\Server\4.2 . notice the space in "Program Files"
export PATH=$PATH:"C:/Program Files/MongoDB/Server/X.X/bin"