Steps for Installing Mongodb Server on Debian 12 Linux

Setting up the MongoDB database server on Debian12 or 11 Linux distros running locally or in the cloud is not a difficult task, however, one must know how to use the terminal and Linux command line. Although MongoDB offers an enterprise edition apart from the community one, here we will perform the steps using the community edition of this free and open-source NoSQL document database software platform.

What do we require for this tutorial?

  • Debian 12 server or desktop
  • User with sudo access
  • An active Internet connection

Let’s see the commands for installing the MongoDB server on a Debian 12 (Bookworm) system.

1. Install Debian 12 Updates

Execute the system update command on the Debian 12 server or desktop because it will refresh the APT repository package cache on the system and also install the latest available updates. Apart from that also download the required common packages such as cURL using the second given command.

sudo apt update
sudo apt install curl wget

 

2. Import the MongoDB Public Key and add the repo

Debian Linux doesn’t offer the package to install MongoDB from its official repository, hence we have to add it manually. Therefore, on your command terminal, first, execute the given command that will add the GPG key required by the system; to check and confirm whether the packages we will get from the Mongo repository are from the official source without any discrepancies or not.

Note: While writing this article, the latest version of the MongoDB was “7.0“, hence we are installing that. In your case, if it is different or you want to get some older version then change the version number – 7.0 in the given commands with the one that you want to install:

Add GPG key:

curl -sSL https://www.mongodb.org/static/pgp/server-7.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/

Add MongoDB Repository:

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

Run the System Update:

Let the system know about your newly added repository by running the system update command:

sudo apt update

3. Installing MongoDB on Debian 12

From here nothing else needs to be done to install MongoDB on Debian except running the given command. Execute it to install MongoDB: database tools, mongosh, extra tools, mongos, database server, and shell.

sudo apt install mongodb-org
Installing MongoDB on Debian 12

4. Start and Enable the 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 --no-pager -l
mongo server service status

Note: If you get the following errors while starting the MongoDB either on a physical machine or VirtualBox, then this means AVX instructions are not supported by your CPU or virtual machine platform.

Process: 1300 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=killed, signal=ILL)
Main PID: 1300 (code=killed, signal=ILL)

or

Illegal instruction

 

4. Check the installed version

To confirm what version is exactly installed on your system, run:

mongod --version

To get the Mongo command line simply type:

mongos --help

To know- how to use the database commands, see the official documentation. 

Mongo Version 7.0 check

5. How to Update

If any security update will be available for MongoDB version 7.0 then to get that we just need to run the system update command.

sudo apt update && sudo apt upgrade

6. 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 autoremove --purge mongodb-org

To remove the added repository and GPG key as well:

sudo rm  /etc/apt/trusted.gpg.d/mongoserver_key.gpg
sudo rm etc/apt/sources.list.d/mongodb-org-7.0.list

 

Other Tutorials:

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.