How to Install MongoDB 5 on Debian 11

1923
Share:
how-to-install-mongodb-5-on-debian-11

MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License (SSPL).

Unlike relational databases, it doesn't consist of tables and rows, but it’s built on an architecture of collections and documents. Documents comprise sets of key-value pairs and are the basic unit of data in it. Collections contain sets of documents and function as the equivalent of relational database tables.

MongoDB is available in two server editions: Community and Enterprise. There is another MongoDB solution called MongoDB Atlas. It is a hosted MongoDB service option in the cloud which requires no installation overhead and offers a free tier to get started.

For general users, the MongoDB Community edition will be enough for testing/developing purposes. We'll cover about MongoDB Community Edition in this article.

Install MongoDB Community Edition

First, we need to create a package management repository configuration file in our Debian 11 Bullseye host. In this article, we'll use mongodb-org-5.0.list as repository's file name and store it under /etc/apt/sources.list.d/ directory. Using your favorite text editor, create the file with content below:

deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main

If you'd like one liner command, you can use this:

$ echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

Create Repository File

Note: We're using buster other than bullseye due to latest available version in MongoDB repository is buster.

Note: If you'd like to install another MongoDB version, adjust accordingly.

After we've created the file, we need to import its GPG key into our Debian 11 system.

$ wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

The operation should respond with an OK.

Import GPG Key

However, if you receive an error indicating that gnupg is not installed, you can:

$ sudo apt-get install gnupg

Once we've created the file and imported its GPG key, we can run apt to install the MongoDB package.

$ sudo apt update
$ sudo apt install mongodb-org

Install MongoDB

When it asks for confirmation, respond with "Y" followed by "Enter" to continue with installation process. Once the installation process finished, we can verify our installation.

Run MongoDB Community Edition

We can start MongoDB service (mongod) using this command:

$ sudo systemctl start mongod

You can verify that the mongod process has started successfully by issuing the following command:

$ sudo systemctl status mongod

To make MongoDB start automatically when the system reboot, enter this command:

$ sudo systemctl enable mongod

Verify MongoDB Installation

Once we verify that our mongod process has started successfully, we can connect to MongoDB server. MongoDB provide an utility (shell) to interact with its database called mongosh.

To start a mongosh session on the same host machine as the MongoDB server (mongod), you can run mongosh without any command-line options:

$ mongosh

Above command means we want to connect to a MongoDB server (mongod) that is running on your localhost with default port 27017.

Final Words

Well, that's it. I hope that you now know how to install MongoDB 5.0 on Debian 11. If you run into any issues or have any feedback feel free to drop a comment below.

Tags Linux
Share:

0 comment

Leave a reply

Your email address will not be published. Required fields are marked *