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 typi
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.
run this command, it works:
brew services start mongodb-community@4.0
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
Make directory for data and set rights:
mkdir -p ~/data/db
chown -R mongodb.mongodb ~/data/db
Run MongoDB:
mongod --dbpath ~/data/db
This worked for me:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
3 steps:
Step 1:
export PATH="$PATH:/usr/local/mongodb/bin"
OR
export PATH="$PATH:/usr/local/opt/mongodb@3.2/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
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