MongoDB is one of the most popular document-oriented NoSQL databases, known for its scalability, flexibility, and high performance.

It stores data in JSON-like documents, making it ideal for web applications, mobile backends, IoT platforms, and enterprise-grade software systems. 

In this step-by-step guide, we’ll show you how to Install MongoDB on Ubuntu 20.04 and configure it for optimal performance.

Whether you’re part of an enterprise IT team, a startup development group, or a solo developer building modern applications, this MongoDB installation guide will help you get started quickly. 

Step 1: Update Your Ubuntu System 

Before you install any new software, it’s essential to update your system to ensure compatibility and security. 

bash 

CopyEdit 

sudo apt update && sudo apt upgrade -y 
 

  • sudo apt update → Fetches the latest package lists. 
  • sudo apt upgrade -y → Installs the latest package versions automatically. 

Step 2: Import MongoDB’s Public GPG Key 

MongoDB packages are signed for authenticity. Import the official GPG key to verify package integrity: 

bash 

CopyEdit 

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

  • wget -qO – → Downloads the key silently. 
  • apt-key add – → Adds the key to your trusted keyring. 

Step 3: Add the MongoDB APT Repository 

Add MongoDB’s official repository to your APT sources list: 

bash 

CopyEdit 

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

Then refresh your package index: 

bash 

CopyEdit 

sudo apt update 
 

Step 4: Install MongoDB Packages 

With the repository set up, you can now install MongoDB on Ubuntu 20.04 using: 

bash 

CopyEdit 

sudo apt install -y mongodb-org 
 

This command installs: 

  • mongod → MongoDB server 
  • mongosh → MongoDB shell 
  • mongos → Sharding router 

Step 5: Start MongoDB Service 

After installation, start MongoDB with systemd

bash 

CopyEdit 

sudo systemctl start mongod 
 

Check its status: 

bash 

CopyEdit 

sudo systemctl status mongod 
 

If you see active (running), MongoDB is successfully running. 

Step 6: Enable MongoDB on Startup 

To ensure MongoDB starts automatically after a reboot: 

bash 

CopyEdit 

sudo systemctl enable mongod 
 

Step 7: Verify MongoDB Installation 

Connect to the MongoDB shell: 

bash 

CopyEdit 

mongosh 
 

Check the version: 

javascript 

CopyEdit 

db.version() 
 

Bonus: Basic MongoDB Commands for Beginners 

Once MongoDB is running, you can try these basic commands: 

  • List Databases 

javascript 

CopyEdit 

show dbs 
 

  • Create/Switch to a Database 

javascript 

CopyEdit 

use mydb 
 

  • Insert a Document 

javascript 

CopyEdit 

db.users.insertOne({ name: “Alice”, age: 30 }) 
 

  • Find Documents 

javascript 

CopyEdit 

db.users.find() 
 

Conclusion 

You have now learned how to Install MongoDB on Ubuntu 20.04 and run it successfully. This powerful database system is capable of handling everything from startup MVPs to enterprise-level applications with millions of records. 

When deploying MongoDB in production, remember to: 

  • Enable authentication 
  • Configure firewall rules 
  • Set up automated backups 

If your business needs expert help in database setup, performance optimization, or enterprise software development, our team at EmbarkingOnVoyage Digital Solutions specializes in delivering secure, scalable, and high-performance systems tailored to your needs. 

Additional Resources: