Back to blog
Jul 03, 2024
3 min read

How to install MongoDB on Debian

MongoDB is a popular open-source document-oriented NoSQL database designed for scalability, flexibility, and high performance.

What is MongoDB?

MongoDB is a popular open-source document-oriented NoSQL database designed for scalability, flexibility, and high performance.

MongoDB offers a flexible, scalable, and high-performance solution for modern application development, especially when dealing with large volumes of diverse data types.

Features:

  • Document-based NoSQL DB.
  • Schema-less, unlike traditional relational databases.
  • Scalability.
  • Querying and Indexing, that means it supports powerful ad-hoc queries, indexing, and real-time aggregation for efficient data retrieval and analysis.
  • Replication and High Availability, MongoDB built-in replication and automatic failover, ensuring data availability and reliability.

User Case

  • An Application dealing with large amounts of unstructured or semi-structured data.
  • An Application provide real-time analytics.
  • Content Management System.
  • Some Application or Projects which needs rapid development and scalability.

The step-by-step guide on how to install MongoDB on Debian:

  1. Import the MongoDB public GPG key:
sudo apt-get install gnupg
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
  1. Create a list file for MongoDB: My VM is Debian 12 “Bookworm”, so I focuse on this linux distro.
echo "deb [signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/7.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
  1. Update the package database and install MongoDB:
sudo apt-get update
sudo apt-get install -y mongodb-org
  1. Start and enable the MongoDB service:
sudo systemctl start mongod
sudo systemctl enable mongod
  1. Verify the installation:
sudo systemctl status mongod
mongod --version

OK, right now, you have already installed MongoDB 7.0 Community Edition on your Debian system. By default, MongoDB binds to localhost (127.0.0.1). To allow remote connections, you’ll need to modify the configuration file.

  1. If I don’t want to use MongoDB In the future, so here is steps to uninstall MongoDB from Debian Linux. These commands will remove MongoDB, its configuration files, and data directories. BE CAREFULLY.
sudo systemctl stop mongod
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb