How To Install MongoDB Server on Ubuntu 24.04 LTS

In this article, we are going to cover How To Install MongoDB Server on Ubuntu 24.04 LTS and create a database in MongoDB server.

MongoDB is a flexible and scalable NoSQL database that uses JSON-like documents, ideal for modern web apps. This guide covers installing MongoDB on Ubuntu 24.04, from adding the official repository to managing the service, ensuring a robust setup for your development needs. By the end, you’ll have a fully functional MongoDB installation.

  • SSH Access with admin privileges
  • Ubuntu 24.04 LTS with minimal installation

update the system packages on Ubuntu 24.04 LTS

sudo apt update

Install curl on Ubuntu 24.04 LTS

sudo apt-get install gnupg curl

import MongoDB GPG Key

curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
How To Install MongoDB Server on Ubuntu 24.04 LTS 1

Create the MongoDB Source List in Ubuntu 24.04 LTS

echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
How To Install MongoDB Server on Ubuntu 24.04 LTS 2

Update the Package Database

sudo apt-get update
How To Install MongoDB Server on Ubuntu 24.04 LTS 3

Install MongoDB server on Ubuntu 24.04 LTS

sudo apt-get install -y mongodb-org
How To Install MongoDB Server on Ubuntu 24.04 LTS 4

Start MongoDB Service

sudo systemctl start mongod
How To Install MongoDB Server on Ubuntu 24.04 LTS 5

Enable MongoDB Service

sudo systemctl enable mongod
How To Install MongoDB Server on Ubuntu 24.04 LTS 6

Verify the Installation

mongod --version
How To Install MongoDB Server on Ubuntu 24.04 LTS 7

To restart Mongodb server on Ubuntu 24.04 LTS

sudo systemctl restart mongod

To stop Mongodb server on Ubuntu 24.04 LTS

sudo systemctl stop mongod

Check error logs in mongodb server

sudo tail -f /var/log/mongodb/mongod.log

login mongodb on Ubuntu 24.04 LTS using command line

mongosh
How To Install MongoDB Server on Ubuntu 24.04 LTS 8

Let’s create a sample database called Numbers:

use numbers
How To Install MongoDB Server on Ubuntu 24.04 LTS 9

Check the currently selected database

db
How To Install MongoDB Server on Ubuntu 24.04 LTS 10

You can add a document to your database using below command

db.collection.insert()
How To Install MongoDB Server on Ubuntu 24.04 LTS 11

To list all created databases , use the following command

show dbs
How To Install MongoDB Server on Ubuntu 24.04 LTS 12

Use below command to drop an existing database.

db.dropDatabase()
How To Install MongoDB Server on Ubuntu 24.04 LTS 13

Now check list of databases by using below command

show dbs
How To Install MongoDB Server on Ubuntu 24.04 LTS 14

We can confirm the database was deleted.

Installing MongoDB on Ubuntu 24.04 is a straightforward process that involves adding the official MongoDB repository, updating the package list, and installing the MongoDB package. Once installed, you can start the MongoDB service and access the MongoDB shell to interact with the database.

By following these steps, you can set up MongoDB on your Ubuntu 24.04 system and utilize its powerful data storage and management features.

Related Articles:

MySQL Database Backups using Python Script

Reference:

Install MongoDB Community Edition on Ubuntu mongodb official page

Harish Reddy

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap