How to Install MongoDB 4.4 on Ubuntu 18.04 & 16.04 via PPA
To install MongoDB 4.4 on Ubuntu 18.04 or 16.04 using a PPA (Personal Package Archive), follow these steps. The installation involves adding the MongoDB 4.4 PPA, installing the MongoDB packages, and configuring the MongoDB service.
1. Import MongoDB 4.4 Public Key
MongoDB requires a public key to ensure the authenticity of the packages being installed.
Import the MongoDB 4.4 public key:
This will add the MongoDB public GPG key to your system.
2. Add the MongoDB 4.4 Repository
Once the key is added, you'll need to add the MongoDB 4.4 repository to your system.
Add the MongoDB repository for Ubuntu 18.04 (Bionic):
For Ubuntu 16.04 (Xenial), replace
bionic
withxenial
:
3. Update Package List
After adding the MongoDB repository, you need to update your system’s package index to include the MongoDB packages.
Update package list:
4. Install MongoDB 4.4
Once the repository is added and the package list is updated, you can proceed to install MongoDB.
Install MongoDB 4.4:
This will install the MongoDB 4.4 package along with its dependencies (
mongod
,mongo
, and other related tools).
5. Start MongoDB Service
After installation, you can start the MongoDB service.
Start MongoDB:
Enable MongoDB to start on boot:
Check the status of MongoDB:
This will show if MongoDB is running. You should see
Active: active (running)
in the output.
6. Verify MongoDB Installation
To verify that MongoDB is correctly installed and running, access the MongoDB shell:
Access the MongoDB shell:
This will bring up the MongoDB shell where you can run commands.
Check MongoDB version:
Once inside the shell, check the version of MongoDB by running:
This should return the version
4.4.x
.
7. Firewall Configuration (Optional)
If your system has a firewall enabled (e.g., ufw
), you will need to allow traffic on MongoDB's default port 27017
to access MongoDB remotely.
Allow port 27017 through the firewall (for
ufw
):For
firewalld
:
8. Enable Authentication (Optional)
For production systems, it's essential to enable authentication to secure MongoDB.
Edit the MongoDB configuration file:
Enable authentication by adding or uncommenting the following:
Restart MongoDB to apply changes:
Create an admin user (optional):
Access the MongoDB shell and create an admin user for authentication:
Switch to the
admin
database and create a user:Authenticate with the new user:
Exit the shell and reconnect using the new user credentials:
9. Uninstall MongoDB (If Necessary)
If you want to uninstall MongoDB, you can do so using the following commands:
Stop MongoDB:
Remove MongoDB packages:
Optionally, remove MongoDB data files:
Summary
- Added MongoDB 4.4 repository via PPA for Ubuntu 18.04/16.04.
- Installed MongoDB 4.4 using
apt-get
. - Started MongoDB and enabled it to start on boot.
- Configured firewall to allow MongoDB access (optional).
- Enabled authentication for better security (optional).
MongoDB 4.4 should now be installed and running on your Ubuntu system. Let me know if you need further assistance or configuration! 🚀