How to Install MongoDB on Ubuntu 22.04: Step-by-step

How to Install MongoDB on Ubuntu 22.04: Step-by-step

Created by eneaslari 2/5/2024

mongodb ubuntu linux

Step 1: Install MongoDB on Ubuntu 22.04

Installing Prerequisite Packages

First, install the necessary packages:

sudo apt install software-properties-common gnupg apt-transport-https ca-certificates -y

Setting Up the MongoDB Repository

Import the MongoDB public key:

curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor

Add the MongoDB 7.0 APT repository:

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

Installing MongoDB

Update your package list and install MongoDB:

sudo apt update
sudo apt install mongodb-org -y

Verify the MongoDB installation by checking its version:

mongod --version

Step 2: Start the MongoDB Service

Checking Service Status

Initially, MongoDB's service is disabled. Check its status:

sudo systemctl status mongod

Starting MongoDB

Start the MongoDB service:

sudo systemctl start mongod

Confirm that the service is active:

sudo systemctl status mongod

Check if the server is listening on the default port (27017):

sudo ss -pnltu | grep 27017

Enabling MongoDB on Boot

Enable MongoDB to start automatically on system boot:

sudo systemctl enable mongod

More to read


My New Plan: Making a Mini-Game Every Week
21/2/2025

This week, I realized that working on big projects can sometimes feel slow, and it’s easy to lose motivation. So, I came up with a new plan—I’ll create and release a small game every week!

Making Tic-Tac-Toe and Sudoku in Just a Few Hours
20/2/2025

This week, I decided to take a break from my main game project and create something simple: **a Tic-Tac-Toe and a Sudoku game**.

How I Made My Game Development Workflow Stress-Free
19/2/2025

Game development can be overwhelming, especially when working on multiple tasks without a clear plan. For a while, I was struggling to organize my thoughts and decide what to focus on next

Designing Fun and Engaging Game Levels
18/2/2025

Creating levels for a game sounds simple, but it comes with its own set of challenges.