Installation
MongoDB Community Server is available for free.
You can download installer for your operating system at https://www.mongodb.com/try/download/community
Install
Download the installer by selecting,
- Version - eg, 6.0.3
- Platform - select your operating system
- Package - select "server"
Linux
Ubuntu
sudo apt-get install libcurl4 openssl liblzma5
Download the installer files.
tar -zxvf mongodb-linux-*-6.0.1.tgz
sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
OR
sudo cp <mongodb-install-directory>/bin/* /usr/local/bin/
RedHat
sudo yum install libcurl openssl xz-libs
Download the installer files.
tar -zxvf mongodb-linux-*-6.0.1.tgz
sudo cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/
OR
sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
macOS
Download the installer files.
tar -zxvf mongodb-macos-x86_64-6.0.tgz
sudo cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/
OR
sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
Windows
Use following options to download Windows graphical MSI Installer
- Version - eg, 6.0.1 (current)
- Platform - select "Windows"
- Package - select "msi"
Double-click the .msi file and follow the instructions.
Docker
Run MongoDB docker
Using docker image mongo. Run MongoDB container with name mongodb and expose port 27017.
docker run --name mongodb -d -p 27017:27017 mongo
Set data directory
docker run --name mongodb -d -p 27017:27017 -v YOUR_LOCAL_DIR:/data/db mongo
Set network
docker run --name mongodb -d --network mynetwork -p 27017:27017 -v YOUR_LOCAL_DIR:/data/db mongo
Set root username and password
docker run --name mongodb -d -e MONGO_INITDB_ROOT_USERNAME=LearnDataNow \
-e MONGO_INITDB_ROOT_PASSWORD=LearnDataNow --network mynetwork -p 27017:27017 \
-v YOUR_LOCAL_DIR:/data/db mongo
Cloud Atlas
MongoDB Atlas is a multi-cloud database service by the same people that build MongoDB. Atlas simplifies deploying and managing your databases while offering the versatility you need to build resilient and performant global applications on the cloud providers of your choice.