MongoDB

How To Install MongoDB on Ubuntu 24.04

Welcome to the Greenhost.Cloud blog! If you’re looking to set up a reliable NoSQL database, MongoDB is one of the best choices available. In this post, we’ll guide you through the process of installing MongoDB on Ubuntu 24.04. This guide assumes you have a basic understanding of command-line operations and that you have administrative access to your system.

Prerequisites

Before we start, ensure you have the following:

  • A system running Ubuntu 24.04.
  • A user account with sudo privileges.
  • An internet connection to download packages and updates.

Step 1: Update Your System

First, it’s a good practice to update your system’s package index to ensure you’re installing the latest versions. Open your terminal and run:

sudo apt update
sudo apt upgrade -y

Step 2: Import the MongoDB Public Key

MongoDB packages are signed with a GPG key. You’ll need to import this key using the following command:

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

Note: Make sure to replace “server-7.0.asc” with the appropriate key corresponding to the version you wish to install.

Step 3: Create MongoDB’s List File

Next, you need to create a list file for the MongoDB repository. Use your text editor to create this file:

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

In this command, replace “focal” with the version name that corresponds to your Ubuntu release if necessary.

Step 4: Update the Package Database Again

Now that you’ve added the MongoDB repository, you’ll need to update the package database again:

sudo apt update

Step 5: Install MongoDB

With the repository added and the package database updated, it’s time to install MongoDB:

sudo apt install -y mongodb-org

This command installs the latest version of MongoDB along with its associated tools.

Step 6: Start the MongoDB Service

After the installation, you need to start the MongoDB service. Use the following command:

sudo systemctl start mongod

To ensure MongoDB starts on boot, enable the service with:

sudo systemctl enable mongod

Step 7: Verify the Installation

To confirm that MongoDB was installed correctly and is running, you can check the status of the service:

sudo systemctl status mongod

You should see output indicating that the service is active (running).

Additionally, you can connect to the MongoDB shell using:

mongo

If you can access the MongoDB shell successfully, congratulations! You’ve installed MongoDB on your Ubuntu 24.04 system.

Step 8: Configure Firewall (Optional)

If your system is running a firewall, you may need to allow incoming traffic on the MongoDB port (default is 27017). You can do this with the following commands:

sudo ufw allow 27017
sudo ufw reload

Conclusion

You now have MongoDB installed and running on your Ubuntu 24.04 system! With its flexible schema and powerful performance, MongoDB can help you manage your data effectively. Be sure to explore its rich features and capabilities.

If you have any questions or run into issues during your installation, feel free to leave a comment below, and we’ll be happy to help you out!

Happy coding with MongoDB!


For more insightful articles on cloud services and database management, stay tuned to the Greenhost.Cloud blog!