Shubham S Nimje logo
Shubham Nimje
MongoDB

Install MongoDB 6.0.3 on Ubuntu 22.04

Install MongoDB 6.0.3 on Ubuntu 22.04
2 min read
#MongoDB

Install MongoDB 6.0.3 on Ubuntu 22.04

Harness the power of MongoDB 6.0.3 on your Ubuntu 22.04 system! This comprehensive guide walks you through the installation process, configuration, and security best practices, ensuring a smooth and secure deployment.

Verify MongoDB Installation

Before you start, check if MongoDB is already installed:

mongod --version

Install MongoDB 6.0.3

Follow these steps to install MongoDB:

  1. Import the MongoDB public GPG Key:

    wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
  2. Create a list file for MongoDB:

    echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
  3. Update the package list and install MongoDB:

    sudo apt update
    sudo apt upgrade
    sudo apt install mongodb-org
  4. Verify the installation:

    mongod --version

Enable and Start MongoDB

  1. Enable MongoDB to start on system boot:

    sudo systemctl enable mongod
  2. Start MongoDB:

    sudo service mongod start
  3. Check MongoDB status:

    sudo service mongod status

Configure MongoDB

  1. Open and edit the MongoDB configuration file:

    sudo nano /etc/mongod.conf
  2. Make the following changes in the config file:

    security:
      authorization: enabled
    net:
      port: 27017
      bindIp: 127.0.0.1
  3. Check if the port is allowed through the firewall:

    sudo ufw status verbose
  4. If the port is not allowed, enable it:

    sudo ufw allow 27017
  5. Restart MongoDB to apply the changes:

    sudo service mongod restart
  6. Confirm if MongoDB is allowing remote connections:

    sudo lsof -i | grep mongo