MongoDB Installation Guide for Ubuntu 24.04

How to install MongoDB

MongoDB is a popular NoSQL database known for its flexibility, scalability, and ease of use. This guide will walk you through installing MongoDB 8.0 community edition on Ubuntu 24.04 LTS (Long Term Support) versions, ensuring a reliable and up-to-date setup.

MongoDB will be suitable to used on following applications :

  • High Data Volume: Social media, IoT
  • Unstructured Data: CMS, document repositories
  • Real-Time Data Processing : Analytics dashboards, gaming apps
  • Geospatial Data : Ride-sharing, mapping
  • Event-Driven Applications : Logging, monitoring
  • Distributed Systems : Cloud apps, microservices
  • Mobile/Web Apps : Mobile platforms, SPAs
  • Personalization Systems : E-commerce, streaming services
  • Big Data/ML : Data lakes, ML pipelines

The installation on Ubuntu 24.04 LTS will be consist of several steps, namely :

  1. Update System Packages
  2. Import the MongoDB 8.0 Community Edition GPG Key
  3. Add the MongoDB 8.0 Community Edition Repository
  4. Install MongoDB 8.0 Community Edition
  5. Start and Enable MongoDB Service
  6. Verify Installation
  7. Configure MongoDB Installation
  8. Login To MongoDB 8.0 Community Edition

Prerequisites

Before proceeding, ensure the following:

  • Ubuntu LTS version: MongoDB supports LTS versions like 20.04, 22.04 and 24.04
  • Sudo privileges: You must have a user with administrative privileges.
  • Updated system: Run sudo apt update && sudo apt upgrade to ensure all packages are up to date.

Step1 : Update System Packages

First, update the package list to ensure your system is up to date:

sudo apt update
sudo apt upgrade -y

Step 2 : Import the MongoDB 8.0 Community Edition GPG Key

MongoDB packages are signed with a GPG key. Import the key to ensure the integrity of the packages:

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

Step 3 : Add the MongoDB Repository

Next, add the MongoDB repository to your system’s package sources list.

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

Update the package database to include the new repository:

sudo apt update

Step 4: Install MongoDB

Install MongoDB using the following command:

sudo apt-get install -y mongodb-org=8.0.0 mongodb-org-database=8.0.0 mongodb-org-server=8.0.0 mongodb-mongosh mongodb-org-mongos=8.0.0 mongodb-org-tools=8.0.0
install MongoDB script on Ubuntu 24.04

Step 5: Start and Enable MongoDB Service

Start the MongoDB service:

sudo systemctl start mongod
sudo systemctl enable mongod
Startup and enable MongoDB services

Step 6: Verify Installation

Check the status of the MongoDB service:

sudo systemctl start mongod
sudo systemctl status mongod
sudo systemctl enable mongod

You should see a message indicating that MongoDB is active and running.

Step 7: Configure MongoDB (Optional)

MongoDB stores its configuration in the /etc/mongod.conf file. You can edit this file to customize your MongoDB instance:

sudo nano /etc/mongod.conf
MongoBD Configuration file

\After making changes, restart MongoDB to apply them:

sudo systemctl restart mongod

Step 8: Login To MongoDB 8.0 Community Edition

Launch the MongoDB shell to ensure everything is working correctly:

mongosh
mongosh on MongoDB 8.0

After login, we will be prompted by the mongosh. On this tutorial we will list all database which was already on the system by submitting command line show dbs, as shown belows :

test> show dbs
admin 40.00 KiB
config 12.00 KiB
local 72.00 KiB

Conclusion

You have successfully installed MongoDB on your Ubuntu LTS system. MongoDB is now ready for use, and you can start building applications that leverage its robust NoSQL capabilities. For more advanced configurations, refer to the MongoDB documentation.

(Visited 76 times, 1 visits today)

You may also like