MongoDB is a document database used in many modern web applications. It is classified as a NoSQL database because it does not rely on a traditional table-based relational database structure.
Instead, it uses JSON-like documents with dynamic schemas, meaning that, unlike relational databases, MongoDB does not require a predefined schema before you add data to a database. You can alter the schema at any time and as often as is necessary without having to set up a new database with an updated schema.
In this tutorial you’ll install MongoDB on an Ubuntu 20.04 server, test it, and learn how to manage it as a systemd service.
To install MongoDB on Ubuntu 20.04, you can follow these steps:
-
Import the MongoDB GPG Key:
Open a terminal and import the MongoDB GPG key to ensure the packages are authentic.
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-archive-keyring.gpg
-
Add the MongoDB Repository:
Add the MongoDB repository to your system's list of sources.
echo "deb [signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
-
Update the Package List:
Update the package list to include the MongoDB packages.
sudo apt-get update
-
Install MongoDB:
Install the MongoDB packages.
sudo apt-get install -y mongodb-org
-
Start MongoDB:
Start the MongoDB service.
sudo systemctl start mongod
You can also enable MongoDB to start on boot:
sudo systemctl enable mongod
-
Verify MongoDB Installation:
Check the status of the MongoDB service to ensure it's running without any issues.
sudo systemctl status mongod
You should see a message indicating that MongoDB is active and running.
Now, MongoDB should be installed on your Ubuntu 20.04 system. You can interact with MongoDB using the mongo shell or connect to it through your preferred programming language.