How To Install MongoDB Server on Debian 11

In this article, we want to teach you How To Install MongoDB Server on Debian 11.

MongoDB is a document-oriented NoSQL database used for high-volume data storage.

Instead of using tables and rows as in the traditional relational databases, MongoDB makes use of collections and documents.

In this guide, we use the MongoDB 5.0 server.

MongoDB 5.0 brings new features such as:

  1. Seamless data redistribution
  2. Multi cloud-security tools
  3. Serverless database on MongoDB Atlas
  4. Native time-series features
  5. Live Resharding
  6. The Versioned API future-proofs your applications.

Set up MongoDB on Debian 11

You need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article about the Initial Server Setup with Debian 11.

As you know, the official repository of MongoDB is only available for Debian 10. You can use the same on Debian 11 as well to install it the same.

First, you need to add the MongoDB repository on Debian 11 with the following command:

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

Then, you need to combine the MongoDB GPG key on Debian 11 to ensure that the packages you will receive to install MongoDB are from an authentic source.

To do this, you can use the following commands:

# curl -sSL https://www.mongodb.org/static/pgp/server-5.0.asc  -o mongoserver.asc
# gpg --no-default-keyring --keyring ./mongo_key_temp.gpg --import ./mongoserver.asc
# gpg --no-default-keyring --keyring ./mongo_key_temp.gpg --export > ./mongoserver_key.gpg
# sudo mv mongoserver_key.gpg /etc/apt/trusted.gpg.d/

Now update your local package index with the following command:

sudo apt update

At this point, you can start to install MongoDB on Debian 11.

Installing MongoDB

You can use the following command to install MongoDB on Debian 11:

sudo apt install mongodb-org

Now you need to start and enable the service with the following command:

sudo systemctl enable --now mongod

Verify that MongoDB is active and running on Debian 11 with the following command:

sudo systemctl status mongod

In your output, you will see:

Output
mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: active (runnning) since Sat 2021-11-06 04:27:30 EDT; 6s ago
Docs: https://docs.mongodb.org/manual
...

Also, with the following command, you can check which version is exactly installed on your server:

mongod --version

You can access the MongoDB command line with the following command:

mongod

To use these database commands you can visit the official documentation.

If you are not interested in MongoDB, you can easily remove it on Debian 11 with the following command:

sudo apt remove mongodb-org

Conclusion

At this point, you learn to Install MongoDB Server on Debian 11.

Hope you enjoy it.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

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

Stay informed and not overwhelmed, subscribe now!