Aman Kumar Singh
Aman Kumar Singh
Aman Kumar SinghView Profile

Home iconHomeAbout iconAboutPortfolio iconPortfolioStack iconStackBlog iconBlogContact iconContact

Mail iconMailLinkedIn iconLinkedInGitHub iconGitHubX iconX

© 2026 Aman Kumar Singh. All rights reserved.

ContactAboutBlog
HomeBlogSetting Up MongoDB on Linux: A Step-by-Step Guide (Debian)
mongodblinuxdebainmongodb setupmongoshmongodmongoose

Setting Up MongoDB on Linux: A Step-by-Step Guide (Debian)

Learn how to install and configure MongoDB on a Linux system with this comprehensive step-by-step guide. From initial setup to basic usage, this tutorial covers everything you need to know to get your MongoDB database up and running smoothly on your Linux server.

Aman Kumar SinghAman Kumar Singh
June 17, 2024
2 min read
288 words
Share:
Setting Up MongoDB on Linux: A Step-by-Step Guide (Debian) - banner image
...
0

Table of Contents

  1. Step 1: Update System Packages
  2. Step 2: Import the MongoDB Public Key
  3. Step 3: Create a MongoDB List File
  4. Step 4: Reload Local Package Database
  5. Step 5: Install MongoDB Packages
  6. Step 6: Start MongoDB Service
  7. Step 7: Verify MongoDB Installation
  8. Step 8: Access MongoDB Shell
  9. Additional Configuration (Optional)
  10. Conclusion

Step 1: Update System Packages

Before installing MongoDB, ensure your system packages are up-to-date.

sudo apt-get update
sudo apt-get upgrade

Step 2: Import the MongoDB Public Key

MongoDB provides a public key to verify the packages.

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

Step 3: Create a MongoDB List File

Create a list file for MongoDB in the sources.list.d directory.

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

Step 4: Reload Local Package Database

Reload the local package database to include the MongoDB packages.

sudo apt-get update

Step 5: Install MongoDB Packages

Install the MongoDB packages using the following command.

sudo apt-get install -y mongodb-org

Step 6: Start MongoDB Service

Start the MongoDB service and ensure it runs on system startup.

sudo systemctl start mongod
sudo systemctl enable mongod

Step 7: Verify MongoDB Installation

Check if MongoDB has been installed correctly by checking its status.

sudo systemctl status mongod

Step 8: Access MongoDB Shell

To start using MongoDB, access the MongoDB shell.

mongo

Additional Configuration (Optional)

You may want to configure MongoDB further for security or performance reasons.

1. Configuration File

MongoDB's configuration file is located at /etc/mongod.conf. You can edit this file to change various settings.

sudo nano /etc/mongod.conf

2. Enable Authentication

To enable authentication, add the following lines under security:

security:
  authorization: enabled

Restart MongoDB to apply the changes.

sudo systemctl restart mongod

3. Create Administrative User

Access the MongoDB shell and create an administrative user.

use admin
db.createUser(
  {
    user: "admin",
    pwd: "password",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

Conclusion

Congratulations! You have successfully installed and configured MongoDB on your Linux system. You can now start building your applications with MongoDB as your database.

Aman Kumar Singh

Written by Aman Kumar Singh

Full Stack Developer passionate about Next.js, React, and building scalable web applications. Sharing insights and tutorials to help developers grow.

View Profile Follow

Share this article

Share on X Share on LinkedIn

Related Articles

Why These AI CEOs Say AI Won't Replace Humans — It Will Empower Them - blog banner
2 min
AI in CodingWeb Development

Why These AI CEOs Say AI Won't Replace Humans — It Will Empower Them

Human-AI Collaboration is the Future At Web Summit Qatar earlier this month, CEOs from two leading AI companies shared their vision for the future of ...

10
3d ago
Google Launches Gemini 3.1 Pro: Double the Reasoning Power - blog banner
1 min
AI in CodingDeveloper Tools

Google Launches Gemini 3.1 Pro: Double the Reasoning Power

Google's Smartest Model Yet Google has released Gemini 3.1 Pro, a major upgrade to their AI model with significantly improved reasoning capabilities. ...

10
4d ago
OpenAI Partners with Reliance to Add AI Search to JioHotstar - blog banner
4 min
AI in Coding

OpenAI Partners with Reliance to Add AI Search to JioHotstar

OpenAI has partnered with Reliance to bring conversational AI search to JioHotstar, India's largest streaming service. Users will be able to search for movies, shows, and live sports using text and voice prompts in multiple languages.

50
4d ago
All Articles
0
0