MongoDB is a popular NoSQL database management system known for its flexibility, scalability, and performance. Installing MongoDB on a Linux Ubuntu 20.04 Server is a relatively straightforward process, and in this guide, we’ll walk you through the steps to get it up and running.
Step 1: Import the MongoDB GPG Key
The first step is to import the MongoDB GPG key to ensure the authenticity of the software packages. Open a terminal and run the following command:
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
This command fetches the GPG key and adds it to your system’s list of trusted keys.
Step 2: Add MongoDB Repository
Next, you’ll need to add the MongoDB repository to your system’s package sources list. Run the following command to add the 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
This command adds the MongoDB repository to the sources list.
Step 3: Update Package Lists
Before installing MongoDB, it’s essential to update the package lists to ensure that you’re installing the latest version available. Run the following command to update the package lists:
sudo apt update
Step 4: Install MongoDB
Once the package lists are updated, you can proceed to install MongoDB using the following command:
sudo apt install -y mongodb-org
This command will install the MongoDB package along with its dependencies. The -y
flag automatically confirms any prompts during the installation process.
Step 5: Start MongoDB Service
After the installation is complete, you need to start the MongoDB service. Run the following command to start the MongoDB service:
sudo systemctl start mongod
You can also enable MongoDB to start automatically at boot time by running the following command:
sudo systemctl enable mongod
Step 6: Verify MongoDB Installation
To ensure that MongoDB is running properly, you can check its status using the following command:
sudo systemctl status mongod
If MongoDB is running correctly, you should see a message indicating that it is active and running.
Step 7: Access MongoDB
MongoDB is now installed and running on your Ubuntu 20.04 Server. You can access the MongoDB shell by running the following command:
mongo
This command will open the MongoDB shell, allowing you to interact with the database.
Congratulations! You have successfully installed MongoDB on your Linux Ubuntu 20.04 Server. You can now start using MongoDB to store and manage your data.
Remember to configure any necessary firewall rules to allow traffic to MongoDB if you haven’t done so already. Additionally, you may want to explore further configuration options and security best practices in the MongoDB documentation.