Learn the simple steps to install MongoDB server and client on Debian 11 to manage local or remote Databases with the help of a command terminal.
MongoDB is a database based on a non-relational document model. As a so-called NoSQL database (NoSQL = Not-only-SQL) it differs fundamentally from conventional relational databases such as Oracle, MySQL, or the Microsoft SQL Server. The name MongoDB is derived from the English word “humongous”, which roughly means “gigantic”.
MongoDB Server & client installation on Debian 11 or 10 Linux
During this article, the official repository of MongoDB is available for Debian 11 Bullseye, hence we can use the same.
1. Add MongoDB Repository on Debian 11
As we know the MongoDB packages are not available to install directly from the base repository of Debian 11 or 10., therefore, we need to add the official one offered by the developers of this NoSQL database.
echo "deb http://repo.mongodb.org/apt/debian bullseye/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
2. Integrate the MongoDB GPG key
To ensure the packages we will receive to install this database on our Linux are from an authentic source. Add the GPG signed key by the developers of the Database server.
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/
3. Run system update
On your Debian 11 or 10 command terminal run the system update command to make sure all the existing packages are up to date.
sudo apt update
4. Command to Install MongoDB on Debian 11 or 10
That’s it. We have configured already what we need to install “database-tools, mongosh, extra tools, mongos; database server and shell” on our Debian 11 or 10 Linux.
Hence, just run a simple command:
sudo apt install mongodb-org
5. Start and Enable MongoDB service
Once the installation is completed, let’s enable and also start the service of the Database server, so that we don’t need to run it again and again with system boot.
sudo systemctl enable --now mongod
to check the status:
sudo systemctl status mongod
6. Check the installed version
To confirm what version is exactly installed on your system, run:
To get the mongo command line simply type:
Whereas to know- how to use the database commands, see the official documentation.
Uninstall or Remove
Well, those who are not interested anymore in MongoDB and don’t require it, can remove the same using the below-given command:
sudo apt remove mongodb-org