In this article, we will have explained the necessary steps to install and configure MongoDB on Ubuntu 18.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.
MongoDB is a free, distributed, and an open-source document database at its core that powers high availability, horizontal scaling, and geographic distribution. It stores data in JSON-like documents and supports Ad hoc queries, indexing, and real-time aggregation.
Install MongoDB on Ubuntu
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Install MongoDB on Ubuntu 18.04.
Now, add the MongoDB GPG key to your system using the following command:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'
Use the following linux command to install MongoDB on Ubuntu 18.04 Bionic server:
sudo apt update sudo apt install mongodb-org
Once the installation is completed, start the MongoDB daemon and enable it to start on boot by typing:
sudo systemctl start mongod sudo systemctl enable mongod
Step 3. Enable Remote MongoDB Access on Firewall.
By default MongoDB runs on port 27017, to allow access from everywhere you can use:
sudo ufw allow 27017
To allow remote MongoDB connections, you need to add your server IP address to /etc/mongodb.conf configuration file as shown:
sudo nano /etc/mongodb.conf
bind_ip = 127.0.0.1,your_server_ip #port = 27017
Save the file, exit the editor, and restart MongoDB:
sudo systemctl restart mongodb
That’s all you need to do to install MongoDB on Ubuntu 18.04. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.