How to Install MongoDB 8 on Ubuntu 24.04
MongoDB 8 on Ubuntu 24.04 sets up a popular, open-source database that stores information in flexible, JSON-like documents instead of rigid tables. MongoDB Community Edition 8.0 brings faster query speeds and better security tools to your system.
Getting this database running on your computer requires adding the official software repository and running a few simple terminal commands. You need a user account with sudo privileges to complete these steps.
Install MongoDB 8 on Ubuntu 24.04 by adding the official repository and using APT. First, install necessary packages with `apt install`, then import the GPG key, add the repository to `sources.list.d`, and finally install with `apt-get install mongodb-org`.
Install MongoDB
To install MongoDB 8 Ubuntu 24.04, you need to update your system package list, install curl, and add the official MongoDB GPG key. This process ensures your system trusts the software source and downloads the correct database files safely before you run the final setup commands.
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 uninstall MongoDB from Ubuntu, you must stop the active database service, remove the software packages, and delete the leftover data directories. Cleaning up these remaining files ensures all database traces and logs are completely gone from your system storage.
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.
Following this guide helps you set up and manage MongoDB, a popular NoSQL database, for your applications on Ubuntu 24.04. This process ensures you have a functional database ready for development.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
[…] How to install MongoDB on Ubuntu […]