How I installed mongodb on my macos (bigsur)
Whats is mongodb
MongoDB is an open-source document database and leading NoSQL database. MongoDB is written in C++. This article will give you an overview of how to install mongodb on your mac os will explain how i went about installing the database in this case i was working on big sur but it should work for other versions of the mac os.
Steps to install the latest version of mongodb
- Head over to the official download page and download the compressed .tgz file.
- Open the terminal and change directory to the Downloads folder
cd Downloads
. - Move the downloaded archive to the home directory —
mv
mongodb-macos-x86_64–4.4.6.tgz~/
. Please note your downloaded version might be updated by the time you are going over this article , not to worry it should work perfectly. - Extract mongodb from the archive
cd ~/ && tar zxvf
mongodb-macos-x86_64–4.4.6.tgz - Move the files into a new folder with a readable name
mv
mongodb-macos-x86_64–4.4.6.tgzmongodb
- Create the folder where mongodb stores data which is
/data/db
. Running the commandmkdir -p /data/db
on macOS Big Sur throws the errormkdir: /data/db: Read-only file system
. So, I created the directory in another folder (the mongodb folder containing the extracted files).cd ~/mongodb && mkdir -p /data/db
.
Now Lets check if everything is running correctly
mongodb always checks that the /data/db
directory exists before it can start up, the mongod
command will fail.
To solve this i had to create some aliases in bash to point mongodb to the proper directory.
Open up your ~/.bash_profile
and add the following commands to the end:
alias mongod='~/mongodb/bin/mongod — -dbpath ~/mongodb/data/db'
alias mongo='~/mongodb/bin/mongo'
Save the file and mongodb installation and setup is complete.
Restart your terminal or run source ~/.bash_profile
and the commands mongod
(for starting up mongodb) and mongo
will both function as expected.
Congratulations you have successfully installed mongodb 🔥 🔥 🔥
Before you go… Thanks for reading the article! If you enjoyed it, please don’t forget to show your appreciation by clicking 👏 👏 below!
Any questions or comments hit me up on
Mail: epmnzava@gmail.com
Twitter: https://twitter.com/epmnzava
Github: https://github.com/dbrax