Linux MintUbuntu Based

How To Install MongoDB on Linux Mint 22

Install MongoDB on Linux Mint 22

In this tutorial, we will show you how to install MongoDB on Linux Mint 22. MongoDB, a powerful and flexible NoSQL database, has become an essential tool for modern application development. Its document-oriented approach and scalability make it a popular choice for handling large amounts of unstructured data. Linux Mint 22, a user-friendly and stable Linux distribution based on Ubuntu, provides an ideal platform for running MongoDB.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the MongoDB NoSQL database on Linux Mint 22.

Prerequisites

  • A server running one of the following operating systems: Linux Mint 22.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • A Linux Mint 22 system with a minimum of 2GB RAM and 10GB free disk space.
  • While we’ll guide you through the process, a basic understanding of the command line will be beneficial. If you’re new to the CLI, you might want to acquaint yourself with some fundamental commands.
  • An active internet connection.
  • Administrative privileges are essential for installing and configuring software on your system. Ensure that you have superuser or sudo access.

Install MongoDB on Linux Mint 22

Step 1. Update Your Linux Mint System.

To begin the installation process, it’s crucial to update your system packages to their latest versions. This ensures that you have access to the most recent security patches and bug fixes. Open a terminal and run the following command to update the package list and upgrade any outdated packages:

sudo apt update
sudo apt upgrade

The apt update command refreshes the package database, while apt upgrade installs the available updates. This step may take a few minutes, depending on the number of packages that need to be updated.

Step 2. Installing MongoDB.

To ensure the authenticity and integrity of the MongoDB packages, you need to import the MongoDB public key. This key is used to verify the digital signature of the packages, preventing any unauthorized modifications. To import the key, execute the following command in your terminal:

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

To enable your system to locate and install the MongoDB packages, you need to create a repository list file. This file contains information about the MongoDB repository, including its URL and the distribution codename. Create the list file by running the following command:

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

With the GPG key imported and the source list file created, we can now install MongoDB. First, update the package lists to include the newly added repository:

sudo apt update

Next, install the MongoDB packages using the following command:

sudo apt install mongodb-org

After the installation is complete, start the MongoDB service and enable it to run automatically on the system boot:

sudo systemctl start mongod
sudo systemctl enable mongod

To verify that MongoDB is running correctly, check the service status using the following command:

sudo systemctl status mongod

If the service is active and running, you should see output similar to:

● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: active (running) since ...

To ensure that MongoDB is installed correctly and functioning as expected, you can check the version of MongoDB installed on your system. Run the following command in your terminal:

mongo --version

Step 3. Secure MongoDB Installation.

While MongoDB is now installed and running on your Linux Mint 22 system, it’s crucial to configure it for enhanced security. By default, MongoDB does not require authentication, which can leave your database vulnerable to unauthorized access. To secure your MongoDB installation, you should enable authentication and create an administrative user.

To enable authentication, open the MongoDB configuration file using a text editor with sudo privileges:

sudo nano /etc/mongod.conf

Locate the #security section in the configuration file and uncomment the security line. Add the following configuration under the security section:

security:
  authorization: enabled

Save and close the file, then restart the MongoDB service for the changes to take effect:

sudo systemctl restart mongod

Now, connect to the MongoDB shell as an unauthenticated user:

mongo

Switch to the admin database:

use admin

Create an administrative user with the necessary privileges:

db.createUser({
  user: "adminUser",
  pwd: "strongPassword",
  roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
})

Replace “adminUser” with your desired username and “strongPassword” with a secure password.

Exit the MongoDB shell by typing exit.

Congratulations! You have successfully installed MongoDB. Thanks for using this tutorial to install the latest version of MongoDB NoSQL database on the Linux Mint system. For additional help or useful information, we recommend you check the official MongoDB website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button