I want to download MongoDB on my iMac. How can I do that?
So far, I’ve tried visiting the official MongoDB website, but I’m unsure about the installation steps. Any help would be greatly appreciated!
???????? Detailed Step-by-Step Guide to Installing MongoDB on macOS (Without Homebrew)
-
Download MongoDB:
Visit theofficial MongoDB website
and download the MongoDB Community Server for macOS. -
Extract the Archive:
Once the download is complete, locate the downloaded file, which is usually a .tgz or .tar.gz archive. Extract it by double-clicking the file or using the terminal:tar -zxvf /path/to/downloaded/mongodb-osx-ssl-x86_64-4.x.x.tgz
-
Move MongoDB to /usr/local:
Move the extracted MongoDB folder to /usr/local for easier access:sudo mv mongodb-osx-ssl-x86_64-4.x.x /usr/local/mongodb
-
Create Data Directory:
MongoDB requires a data directory to store its data. Create the directory using:sudo mkdir -p /usr/local/var/mongodb
-
Set Permissions:
Set the appropriate permissions for the data directory to ensure MongoDB can read and write to it:sudo chown -R $(whoami) /usr/local/var/mongodb
-
Add MongoDB Binaries to PATH:
To access MongoDB commands from any location in the terminal, add the MongoDB binaries to your shell’s PATH. If you are using Zsh, edit your Zsh configuration file (usually ~/.zshrc):nano ~/.zshrc
Add the following line at the end of the file:
export PATH="/usr/local/mongodb/bin:$PATH"
Save and exit the editor.
-
Restart Zsh or Source the Configuration:
Apply the changes made to the configuration file by restarting Zsh or sourcing the updated configuration:source ~/.zshrc
-
Start MongoDB:
Start MongoDB by running the following command in the terminal:mongod --dbpath /usr/local/var/mongodb
-
Verify Installation:
Open a new terminal window and start the MongoDB shell to verify the installation:mongo
You should see the MongoDB shell prompt if everything is set up correctly.
-
Explore MongoDB:
You’re ready to explore MongoDB! Use commands like show dbs to list databases and use your_database_name to switch to a specific database. -
Stop MongoDB (Optional):
If you need to stop MongoDB, press Ctrl + C in the terminal where MongoDB is running.
✅ If you want to check that your MongoDB server will run, type the following command in the terminal:
`brew services start [email protected]`
???? To stop the MongoDB server, type the following command in the terminal:
`brew services stop [email protected]`
???? For better understanding, just watch the video by clicking on the link: