Installing MongoDB
MongoDB is a NoSQL database that has fully flexible index support and a rich queries database.
This document explains how to install MongoDB (as root/sudo
).
Step 1 – Setup Apt Repository
First of all, import GPK key for the MongoDB apt repository on your system using the following command. This is required to test packages before installation
Then add MongoDB APT repository url in /etc/apt/sources.list.d/mongodb.list.
Ubuntu 18.04 LTS:
Step 2 – Install MongoDB on Ubuntu
After adding required APT repositories, use the following commands to install MongoDB on your systems. It will also install all dependent packages required for MongoDB.
If you want to install a specific version of MongoDB, define the version number as follows:
Step 3 – Manage MongoDB Service
After installation, MongoDB will start automatically. To start or stop MongoDB use an init script. For example:
And use the following commands to stop or restart the MongoDB service.
Step 4 – Verify MongoDB Installation
Finally, use the below command to check the installed MongoDB version on your system.
And check the status with:
Important: Some versions have the service name as mongod
and some have mongodb.
If you get an error with the above command, use sudo service mongodb status
instead.
Step 5 - Test MongoDB
Also, connect MongoDB using the command line and execute some test commands for checking proper working.
Last updated