Reputation: 549
I am trying to test MongoDB and I have it all downloaded and moved into the root folder. I can navigate to the folder that holds the mongod, but when I try to run it by typing "mongod" into my terminal, I get a message that says:
"mongod: command not found"
Upvotes: 34
Views: 154971
Reputation: 286
for me i Used the latest version of mongoDb ([email protected]) and for that we should use mongosh instead of mongod
Upvotes: 0
Reputation: 2217
If you’re using mongodb version 6.0, and above, the command you’d need to use for entering the mongodb shell is changed from mongo to mongosh:
$ mongosh
And that’s it✅😃! Yeah! It’s really that simple (as long as this is actually the problem in your specific scenario).
Upvotes: 1
Reputation: 191
This answer is a little bit unrelated, but if you using vscode & would like to interact with mongoDB using command line, have a read.
I was looking to use mongod command as well (as i love to use command to interact with mongoDB), but after several attempts of install i completely give up. Until i found this, the mongoDB vscode extension.
The extension is loading the data pretty fast just like mongod command compare to mongo compass. It allow you to perform CRUD & aggregation in the mongoDB playground, and most importantly you able to retrieve the command on next execution by storing your command in a file with .mongodb extension.
*Update: After using it several weeks, everything is nice, just need to make sure you connecting to the right mongoDB connection (if you establish few different connection)
Upvotes: 0
Reputation: 211
I received the same error message because I used the wrong command to run mongod
(meant for M1s) for my 2019 MacBook with an Intel processor. You can skip past Homebrew updates and MongoDB installation but here's how I resolved my issue:
Download Xcode Command Line tools.
xcode-select --install
Allow Homebrew to add and access MongoDB:
brew tap mongodb/brew
Update Homebrew:
brew update
Install MongoDB Community Edition (@6.0 is the latest version at the time of this post):
brew install [email protected]
macOS with Intel processors:
mongod --config /usr/local/etc/mongod.conf --fork
macOS with Apple M1 processors:
mongod --config /opt/homebrew/etc/mongod.conf --fork
Then open the shell:
mongosh
Or just run mongod
.
Official documentation on installation here.
Upvotes: 17
Reputation: 7955
I was looking for the same and later I have found that now it's very straight forward to install the new MongoDB Community Edition like below:
brew tap mongodb/brew
Note: If you haven't yet install brew
then follow this link: https://brew.sh/#install
brew update
brew install [email protected]
mongod
servermongos
sharded cluster query routermongosh
brew services start [email protected]
mongod
running as a macOS service, use the following command as needed:brew services stop [email protected]
Upvotes: 1
Reputation: 161
If you use brew then check the path:
brew list
brew list mongodb-community@...
then add it to .zshrc
after that use mongosh
instead of mongo
Upvotes: 0
Reputation: 379
MongoDB 5.0 issue resolved - SEP/2022
do following steps
step 1: open a .zshrc file if it does not exist it will create by itself by following the command. For opening or creating a .zshrc file below command is the same.
vim .zshrc
step 2: insert value in it by pressing 'i'
step 3: insert the below command there or paste it there.
export PATH="$PATH:/usr/local/opt/[email protected]/bin"
step 4: to exit click on esc key and the write :wq
step 5: Close the terminal and reopen it and type the below command
mongo
Output
MongoDB shell version v5.0.11
connecting to: mongodb://127.0.0.1:279021/?
compressors=disabled&gssapiServiceName=mongodb
Successfully integrated mongo 🎉 🎉 🎉
happy coding !!
Upvotes: 0
Reputation: 13056
For example, install 64bit MongoDB 2.6.12 on macOS Catalina. (for newest versions you may go to https://www.mongodb.com/download-center/community for your platform).
Download, extract and move:
wget http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.12.tgz
tar xzf mongodb-osx-x86_64-2.6.12.tgz
mv mongodb-osx-x86_64-2.6.12/ /usr/local/mongodb/
Add to file ~/.zshrc
this:
export PATH="$PATH:/usr/local/mongodb/bin"
PS: .bash_profile
or .profile
not worked in my case
Reload terminal (or close, open it):
source ~/.zshrc
Make directory for data and set rights:
mkdir -p ~/data/db
chown -R mongodb.mongodb ~/data/db
Run MongoDB:
mongod --dbpath ~/data/db
Upvotes: 12
Reputation: 615
I have installed [email protected]
, was facing the same issue. I followed below steps.
open bash profile in any editor (you can also try - vi ~/.bash_profile
)
write this export PATH="$PATH:/usr/local/opt/[email protected]/bin"
& save.
do this . source ~/.bash_profile
Upvotes: 3
Reputation: 549
"Mongod" isn't a stand-alone command. You need to run the command like this:
./mongodb/bin/mongod
I used this webpage to help me answer this question.
Upvotes: 14
Reputation: 2118
I was trying to install a previous version (3.6) using latest documentation (4.2 is already released). So, they now call it [email protected]
.
In order to update PATH for such setup, the statement should be
export PATH="$PATH:/usr/local/opt/[email protected]/bin";
I got hint from @retroGiant 's answer
Upvotes: 5
Reputation: 672
run this command, it works:
brew services start [email protected]
Upvotes: 3
Reputation: 557
This worked for me:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
Upvotes: 13
Reputation: 1134
In root directory
sudo mkdir data
cd data
mkdir db
then
sudo chown -R yourUsername /data/
copy path of your mongodb/bin downloaded folder (I suggest you put it in home folder not root dir)
in terminal
export PATH="paste the link here :$PATH"
now it should work but if not
In case you are using different Unix shell and trying to execute mongod within visual studio code( for example ), make sure to read the documentation to link PATH.
For example, if you are using zsh create .zprofile in your home directory.
touch .zprofile
copy your previously made PATH into .zprofile
Now everything should work as expected.
Upvotes: 2
Reputation: 127
3 steps:
Step 1:
export PATH="$PATH:/usr/local/mongodb/bin"
OR
export PATH="$PATH:/usr/local/opt/[email protected]/bin"
(replace version number with your local version)
The first step will allow you to run the command, but will get you another error: "/data/db does not exit" so you have to
Step 2 :
sudo mkdir -p /data/db
Now /data/db is read only, but it has to be writable also so
Step 3 :
sudo chown -R USERNAME /data/db
Upvotes: 5
Reputation: 591
Both answers above are correct. You can either specify the path in one of the following files: .profile, .bashrc, or .bash_profile
export PATH="$PATH:/usr/local/mongodb/bin"
then call the daemon or the shell directly
mongod
mongo
Or for the commands not in the $PATH, use ./mongo or ./mongod from the directory containing these files. This solution can be verbose has you will have to eventually append the whole path when calling these commands from another directory.
/usr/local/mongodb/bin/mongod
or
/usr/local/mongodb/bin$ ./mongod
Upvotes: 31
Reputation: 207345
You need to add the name of the folder that contains the command mongod
into your PATH so your shell knows where to find it.
So, if mongod
is in /usr/bin/freddyfrog, you would edit ~/.profile
and find the line that says PATH=
and edit it to look like this:
export PATH=${PATH}:/usr/bin/freddyfrog
Then login again to make it take effect.
Upvotes: 7