How to Install MongoDB 8 on Ubuntu 24.04

This article explains installing MongoDB 8 Community Edition (LTS) on Ubuntu 24.04.

MongoDB is a popular NoSQL database that stores data in a flexible, JSON-like format, allowing for dynamic schemas and easy scalability. MongoDB offers a more flexible way to store data, which is advantageous for applications with changing data requirements.

The document model makes it easier to understand and manipulate data, especially for applications that deal with complex data.

Installing MongoDB on Ubuntu offers a reliable solution for applications that need flexibility, scalability, and performance.

The steps below will install MongoDB 8.0 Community Edition. Select the appropriate version from the version page to install a different MongoDB Community.

Install MongoDB

To begin, please install the following packages to help you set up MongoDB.

sudo apt update
sudo apt install curl apt-transport-https gnupg

Next, import the MongoDB public GPG key.

curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor

Then, add the repository.

echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

Finally, update and install CouchDB.

sudo apt-get update
sudo apt-get install mongodb-org

Start MongoDB

You can start the mongod process by issuing the following command:

sudo systemctl start mongod
sudo systemctl enable mongod

Verify that MongoDB has started successfully.

sudo systemctl status mongod

The command should output something similar to the one below.

mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; preset: >
Active: active (running) since Fri 2025-03-14 09:43:12 CDT; 3s ago
Docs: https://docs.mongodb.org/manual
Main PID: 16283 (mongod)
Memory: 88.3M (peak: 88.5M)
CPU: 201ms
CGroup: /system.slice/mongod.service
└─16283 /usr/bin/mongod --config /etc/mongod.conf

Stop and restart MongoDB

sudo systemctl stop mongod
sudo systemctl restart mongod

Remove / Uninstall MongoDB

To remove MongoDB from a system, you must delete the MongoDB applications, configuration files, and any directories containing data and logs.

First, stop MongoDB services.

sudo service mongod stop

Then, remove the package and directories.

sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

That should do it!

Conclusion:

Installing MongoDB 8 Community Edition on Ubuntu 24.04 is a straightforward process that offers a flexible and powerful solution for managing data. Here are the key takeaways:

  • Flexibility: MongoDB allows for dynamic schemas, making it suitable for applications with evolving data requirements.
  • Scalability: Its document-based approach easily accommodates data growth and changing applications.
  • Performance: MongoDB is designed to handle high loads, ensuring efficient performance under various workloads.
  • Easy Installation: The installation steps provided are simple to follow, enabling quick deployment of MongoDB.
  • Comprehensive Management: MongoDB services can be easily managed with basic system commands for starting, stopping, and uninstalling.

By following this guide, you can successfully set up and manage MongoDB for your applications on Ubuntu.

Frequently Asked Questions

What are the system requirements for installing MongoDB 8 on Ubuntu 24.04?

To install MongoDB 8 on Ubuntu 24.04, you need a 64-bit version of Ubuntu, at least 2 GB of RAM, and sufficient disk space for your data. It's also recommended to have an internet connection for downloading packages.

How do I start MongoDB after installation?

After installing MongoDB, you can start it by running the command 'sudo systemctl start mongod'. To ensure it starts automatically on boot, use 'sudo systemctl enable mongod'.

How can I verify if MongoDB is running on my system?

You can check if MongoDB is running by executing 'sudo systemctl status mongod'. If it's active and running, you will see a status message indicating that the service is operational.

What should I do if I want to uninstall MongoDB from Ubuntu?

To uninstall MongoDB, first stop the service with 'sudo service mongod stop'. Then, remove the package and associated directories using 'sudo apt-get purge mongodb-org*' and 'sudo rm -r /var/log/mongodb /var/lib/mongodb'.

Is MongoDB suitable for all types of applications?

MongoDB is particularly well-suited for applications that require flexibility and scalability, such as those with evolving data requirements. However, for applications needing complex transactions or strict consistency, a relational database may be more appropriate.

Categories:

One response to “How to Install MongoDB 8 on Ubuntu 24.04”

  1. […] How to install MongoDB on Ubuntu […]

Leave a Reply

Your email address will not be published. Required fields are marked *