TroubleChute Logo
MONGODB

Installing & Using MongoDB on Ubuntu/Debian


Published: Jan 15, 2024
Last Edit: Jan 15, 2024
Linux MongoDB
392 Words, 2 Minutes.

Watch the video:


Timestamps:
0:00 - Intro/Explanation
0:23 - Installing MongoDB
1:05 - Starting MongoDB Server

Introduction

MongoDB is a popular and powerful NoSQL database that provides scalability, flexibility, and ease of use for developers. In this guide, we will walk you through the process of installing and using MongoDB on Ubuntu/Debian Linux. Whether you are a beginner or an experienced user, this step-by-step tutorial will help you set up your own MongoDB server and connect to it from anywhere.

While this article should be up to date for the most up to date, detailed install instructions, please see the following link: https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-debian/

Installing MongoDB Community Edition

Before installing MongoDB, it is important to ensure that your Ubuntu/Debian Linux system is up to date and has the necessary dependencies. Open a terminal and run the following commands:

1
2
3
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install gnupg curl

Installing MongoDB

Instead of going through the instructions and incredible detail, here’s the important bits to installing.

1
2
3
4
5
6
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
   --dearmor
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/7.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org

Connecting to MongoDB

You can use the mongo command locally to Connect to and use the Mongodb server. Otherwise you can use something like a MongoDB compass, which is much better and much more granular control as it’s a gui interface.

You can download MongoDB compass here.

Configuring Bind IP for Remote Connections

By default, MongoDB binds to the 127.0.0.1 IP address, which allows connections only from the local machine. If you want to connect to the MongoDB server from remote machines, you need to modify the bind IP configuration.

Open the MongoDB configuration file using a text editor:

1
sudo nano /etc/mongod.conf

Find the net.bindIp setting and change the value to 0.0.0.0 to allow connections from all IP addresses:

1
2
3
4
# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0

Save the file and exit the text editor.

If you’re using a firewall, that’s also a good idea to an mongo through it using the following command for UFW:

1
sudo ufw allow 27017

Uninstalling MongoDB

Should you ever choose to uninstall Mongodb, simply run the following commands:

1
2
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
TroubleChute © Wesley Pyburn (TroubleChute)
Support Me Privacy Policy Cookies Policy Terms of Service Change privacy settings Contact