How to Install and Use MongoDB on Linux Mint

In the world of database solution, MongoDB is a relative newcomer. However, it has quickly gained enormous popularity because of the features it offers. MongoDB is a general-purpose, cross-platform, document-based database solution that falls under the NoSQL classification. It doesn’t follow the rules of traditional relational databases (for example, MySQL). Instead, it uses JSON-like documents for storing data. In this article, let’s check out how to install and use MongoDB on Linux Mint.

MongoDB on Linux Mint

MongoDB is an open-source cross-platform NoSQL database solution. As it’s a NoSQL database, it’s free from the restricted nature of the traditional databases (for example, MySQL), offering more flexibility for storing data. MongoDB can also be treated as a file storage solution! MongoDB offers efficient scaling, thanks to its sharding feature.

There are two editions of MongoDB available to the customers – the Community and Enterprise version. Now, for general users, the MongoDB Community edition will be enough for testing/developing purposes. However, for large-scale implementation, it’s a good idea to get the Enterprise one. MongoDB Enterprise comes with additional features like customer support, Kubernetes integration, faster memory performance, certification, etc. Check out MongoDB Enterprise Advanced.

In this article, however, I’ll be showcasing how to install and use the MongoDB Community edition.

Install MongoDB on Linux Mint

There are multiple ways we can install MongoDB. Because of its popularity, it’s already a part of the Ubuntu package servers. Linux Mint, being an Ubuntu derivative, can directly grab MongoDB from the package server. However, the official recommendation of MongoDB is to use its own repository for installing the database software.

Ready? Let’s jump right into it!

Install MongoDB from Ubuntu package server

MongoDB is directly available from the Ubuntu package server. All you need is to tell APT to grab and install the mongodb package. Although it’ll work just fine, according to official MongoDB documentation, it’s not recommended method. Follow it at your own responsibility.

First, fire up a terminal and update the APT cache.

$ sudo apt update

Now, tell APT to install MongoDB.

$ sudo apt install mongodb

Install MongoDB from MongoDB repo

MongoDB officially offers repo for Ubuntu, Debian, SUSE Linux, and Amazon. MongoDB officially recommends this method of installing MongoDB. This makes sure that you’re always using the latest version. Linux Mint is Ubuntu-based, so the Ubuntu repo will work just fine.

Note: The repo is version-dependent. This method will showcase the installation of the current latest MongoDB stable version (MongoDB 4.2). For other versions, check out the MongoDB installation document.

Fire up a terminal and start running the following commands. First, let’s check out if GnuPG is installed. GnuPG comes preinstalled with Linux Mint. However, if it was uninstalled previously, then this command will install it right away.

$ sudo apt update && sudo apt install gnupg -y

Now, add the public GPG key of MongoDB repo.

$ wget -qO - | sudo apt-key add -

APT is ready to communicate with the MongoDB repo. Add the MongoDB repo in the list of APT package servers.

$ echo "deb [ arch=amd64,arm64 ] bionic/
mongodb-org/4.2 multiverse"
| sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

Update the APT cache.

$ sudo apt update

The MongoDB repo is added successfully. Now, tell APT to install MongoDB. The package name is mongodb-org. Note that mongodb is from Ubuntu repo whereas mongodb-org is from MongoDB repo.

$ sudo apt install mongodb-org

Using MongoDB

Once the installation is complete, let’s make sure that MongoDB is running. Run this command in the terminal.

$ mongo

The command threw some error. It’s because MongoDB, by default, doesn’t start with boot. To fix this, run the next two command. Essentially, we’re telling systemctl to start and enable MongoDB service at boot.

$ sudo systemctl start mongod
$ sudo systemctl enable mongod

Check MongoDB once again.

$ mongo

Voila! MongoDB is running perfectly! It’s the MongoDB shell that’s running. It serves as the MongoDB control center. MongoDB has its own commands and functions. The following command will print a shortlist of available commands and functions.

$ help

Final thoughts

MongoDB is a powerful database software. It’s even incorporated by Google, Facebook, PayPal, EA, Adobe, eBay etc. giants. Check out companies using MongoDB. That, by itself, is a testimony of the power of MongoDB.

This article just discusses how to install MongoDB. There is a lot to learn about it. You can find plenty of tutorials on the internet on getting started with MongoDB. Check out this beginner’s guide to MongoDB.


About the author

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.