How to Install MongoDB on Ubuntu 20.04 (Community Edition Tutorial). MongoDB server is an open-source NoSQL database that has been gaining popularity in recent years.
MongoDB is a cross-platform document-oriented database program. It can be used on different platforms and languages like Perl, Java, C++, Ruby, Python, etc.
In this article, we will introduce MongoDB, its features, and benefits, and then we will move on to its installation of its Community Edition on Ubuntu 20.04.
What is MongoDB
MongoDB is a free and open-source cross platform and document oriented database program that is classified as a NoSQL or non relational database program. It has several advantages over relational databases, including dynamic schemas, native JSON support and rich aggregation operations.
It is a scalable, high performance database that stores data in JSON like documents with dynamic schemas. Documents are stored in collections and each collection can have a different schema.
MongoDB is written in C++ and has its own query language, called JavaScript Object Notation (JSON). This makes it easy to manipulate data in the database. It also supports indexing and geospatial queries.
It provides the platform for adding new functionality through its plugin architecture. The developers of MongoDB also provide a rich set of drivers for integrating with other programming languages such as C#, Java and Python.
MongoDB platform is easy to scale, provides high availability and offers rich features to build applications. MongoDB is an open source database that allows developers to work with data in real time, store and access it from any device, and run several queries at once.
It runs on Linux, OS X, Windows, Solaris, FreeBSD and OpenBSD.
How to Install MongoDB on Ubuntu 20.04 (Community Edition Tutorial)
If you have already installed MongoDB by its default package in the Ubuntu repository, you will need to remove it because MongoDB in the Ubuntu repository is not maintained by MongoDB Inc.
Then you can proceed with the following process to install the MongoDB community edition directly from its official repository.
Import Public GPG Key of MongoDB Repository
Run the following wget command to import the MongoDB public GPG key.
Add the MongoDB repository to the source list file with the following command. This will ensure that the latest official mongodb-org package will be installed on your system.
Install MongoDB on Ubuntu 20.04 (Community Edition Tutorial)
Now that the official repository has been added to the source list, you can run the simple apt command to install the latest version of MongoDB on your system.
Run the following command to install the mongodb-org package.
sudo apt-get install mongodb-org -y
Output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libfwupdplugin1 linux-headers-5.11.0-36-generic linux-hwe-5.11-headers-5.11.0-36
linux-image-5.11.0-36-generic linux-modules-5.11.0-36-generic
linux-modules-extra-5.11.0-36-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
mongodb-database-tools mongodb-mongosh mongodb-org-database mongodb-org-database-tools-extra
…
Start and Manage the MongoDB Service
Start and Stop the MongoDB Service
You can start the MongoDB service using the following command.
sudo systemctl start mongod
To stop the MongoDB service, run the following command.
sudo systemctl stop mongod
Check the MongoDB Service Status
Run the following command to check and verify the status of the MongoDB service.
sudo systemctl status mongod
Output:
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: active (running) since Thu 2022-06-09 04:51:49 PDT; 12s ago
Docs: https://docs.mongodb.org/manual
Main PID: 57105 (mongod)
Memory: 63.1M
CGroup: /system.slice/mongod.service
└─57105 /usr/bin/mongod --config /etc/mongod.conf
Jun 09 04:51:49 ubuntu-VirtualBox systemd[1]: Started MongoDB Database Server.
…
Current Mongosh Log ID: 62a1df5ce7b9f2ebcf431a16
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.5.0
Using MongoDB: 5.0.9
Using Mongosh: 1.5.0
...
or Run the following command.
mongosh "mongodb://localhost:27017"
Configure Remote Access
To allow MongoDB to be accessed remotely, you need to edit the /etc/mongod.conf configuration file.
Open the /etc/mongod.conf configuration file in the nano editor.
sudo nano /etc/mongod.conf
You will see the following network interfaces section in the file.
How to Install MongoDB on Ubuntu 20.04 (Community Edition Tutorial) Conclusion
In this guide, we have shown you how to install MongoDB Community Edition on Ubuntu 20.04. MongoDB is an open source document database that provides high performance, high availability, and easy scalability.
MongoDB can be used to power next generation applications through its robust features and native read/write interface for JavaScript, making it a powerful choice for web developers and entrepreneurs.
Explore our other content on MongoDB if you want to know more.
Information Security professional with 4+ years of experience. I am interested in learning about new technologies and loves working with all kinds of infrastructures.
51vote
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.