Introduction

MongoDB is a popular NoSQL database known for its flexibility and scalability. This guide provides detailed instructions on how to install MongoDB 4 on an Ubuntu 22.04 system.

Prerequisites

Before you begin, ensure you have the following:

  • An Ubuntu 22.04 system with root or sudo access.
  • Basic knowledge of terminal commands.

Step 1: Import the MongoDB GPG Key

First, import the MongoDB public GPG key used for package signing:

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

Step 2: Create a List File for MongoDB

Next, create the /etc/apt/sources.list.d/mongodb-org-4.4.list file to add the MongoDB repository:

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

Step 3: Update the Package Database

Refresh your package database with the newly added MongoDB repository:

sudo apt update

Step 4: Install MongoDB Packages

Now, install the MongoDB packages:

sudo apt install -y mongodb-org

Step 5: Start and Enable MongoDB

After the installation, start the MongoDB service and enable it to start on boot:

sudo systemctl start mongod

sudo systemctl enable mongod

Step 6: Verify MongoDB Installation

Check the status of MongoDB to ensure it is running correctly:

sudo systemctl status mongod

You should see an output indicating that the MongoDB service is active and running.

Step 7: Secure MongoDB (Optional)

For added security, you may want to enable authentication and create an administrative user. Follow these steps:

  1. Edit the MongoDB configuration file:

sudo nano /etc/mongod.conf

  1. In the file, under #security, add the following lines:

security:

authorization: "enabled"

  1. Restart MongoDB to apply the changes:

sudo systemctl restart mongod

  1. Connect to the MongoDB instance:

mongo

  1. In the MongoDB shell, switch to the admin database and create an administrative user:

use admin

db.createUser(

{

user: "admin",

pwd: "secure_password",

roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]

}

)

Replace secure_password with a strong password.

Conclusion:

You have successfully installed MongoDB 4 on your Ubuntu 22.04 system. You can now start using MongoDB for your database needs. Remember to regularly update and secure your MongoDB instance to keep it running smoothly and securely.

Was this answer helpful? 0 Users Found This Useful (0 Votes)

 

Best price on the market

We guarantee that the price here is always the best for you

Reliable

Holding the top 1 position in .VN registrations for more than 2 decades, data provided by Vietnam Internet Center VNNIC

19 years of leadership

More than 19 years in the field of providing dedicated servers, domain names, business email, cloud servers and Internet value-added service solutions

24/7 support

Our customer support center is always online and ready to help you at all times, call now on +84-8-37.180.217

Fastest Connection Speeds Across Vietnam, Asia, and the USA

Our servers deliver the fastest connection speeds in Vietnam, Asia, and the USA for your business needs.

Located in Quang Trung Software City

Our data centers are situated in Quang Trung Software City (QTSC), Vietnam’s largest and most advanced IT park.

Secure, Reliable, and High-Performance Servers

We offer secure, reliable servers with ultra-fast performance and expert support to ensure your operations run smoothly.

Transparent Pricing with No Hidden Fees

Our pricing is clear with no hidden fees, and you can test our services anytime before making your decision.

0
Happy Clients
0
Dedicated Servers
0
Questions Answered
0
Years of Experience
QTSC Logo VNNIC Logo Dell Logo DirectAdmin Logo FPT Logo ResellerClub Logo
VNS QTSC Intro ❤
❤ 3020 Followers

Reg No. & Tax Code: 0312343115
A Different Orient


PayPal Logo Western Union