Install MongoDB On Mac M2 Without Home-brew
Step 1: Go to MongoDB’s official site and click on “Install on OS X” from the Installation section.
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-os-x/
Step 2: Scroll down to find the Manual Installation Process.
Note: 1 >> In the above image, we have to create a folder called MongoDB in our root directory example : codallt@systemss-MacBook-Air ~ % mkdir -p mongodb
Then to copy the content from your extracted/unzipped folder(i.e., content inside of your mongodb-osx-x86_64-3.0.15) and paste it inside your mongodb folder that you have created use the second command provided in the step 3 in the above image.
codallt@systemss-MacBook-Air ~ % cp -R -n mongodb-osx-x86_64-3.0.15/ mongodb
Note 2 >> As mentioned in the image step 4, add the location of your mongodb bin folder into PATH(In you ~/.zshenv or ~/.bashrc)
export PATH=/Users/username/mongodb/bin
Step 3: Create a data directory in your root location i.e .., where you created the mongodb folder.
codallt@systemss-MacBook-Air ~ % sudo mkdir -p data
codallt@systemss-MacBook-Air ~ % cd data
codallt@systemss-MacBook-Air data~ % sudo mkdir -p db
Step 4: Go to the root directory and give permission to data/db as follows.
codallt@systemss-MacBook-Air ~ % sudo chown -R $USER data/db
Step 5: Run the mongodb as follows.
codallt@systemss-MacBook-Air ~ %./mongodb/bin/mongod --dbpath ~/data/db
Step 6: Check the status of the mongodb server.
codallt@systemss-MacBook-Air ~ % ps ax|grep mongod
OR
ps -ef | grep mongod | grep -v grep | wc -l | tr -d ' '
This will get you the number of MongoDB processes running, thus if it is other than 0, then you have MongoDB running on your system.
Step 7: To kill the mongodb instance
codallt@systemss-MacBook-Air ~ % sudo kill 45429
Step 8: Start Mongo Client
To start the Mongo client, run the below command
codallt@systemss-MacBook-Air ~ % ./mongodb/bin/
You will get below logs if your client is up and running
codallt@systemss-MacBook-Air ~ % ./mongodb/bin/
2024-01-13T13:17:48.652+0530 I CONTROL machdep.cpu.extfeatures unavailable
MongoDB shell version: 3.0.15
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2024-01-13T12:51:02.152+0530 I CONTROL [initandlisten]
2024-01-13T12:51:02.152+0530 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
>
Step 9 : set PATH to mongo and mongod
open your .bash_profile or any other file where you have other path variables and update the below paths.
export MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO_PATH/bin
Step 10: Run mongod and mongo anywhere from terminal
Step 1 : Start the MongoDB server as follows by providing the <db path>
codallt@systemss-MacBook-Air ~ % mongod --dbpath ~/data/db
Step 2 : Now open another terminal tab and Start the mongo client as follows
codallt@systemss-MacBook-Air ~ % mongo
Awsome! Very useful.