Steps of Installing MongoDB Community Edition on Ubuntu


Table of Contents

  1. Overview
  2. Considerations
  3. Import the Public Key
  4. Create a List File for MongoDB
  5. Reload Local Package Database
  6. Install MongoDB Packages
  7. Run MongoDB Community Edition
  8. Uninstall MongoDB Community Edition
  9. Additional Information

Overview

This guide will walk you through the process of installing MongoDB 7.0 Community Edition on Ubuntu Linux using the `apt` package manager. MongoDB is a popular NoSQL database that offers high performance, high availability, and easy scalability.

Considerations

Before proceeding with the installation, please note the following:

  • MongoDB 7.0 Community Edition supports 64-bit Ubuntu LTS releases on x86_64 architecture:
    • 22.04 LTS ("Jammy")
    • 20.04 LTS ("Focal")
  • ARM64 architecture is supported on select platforms.
  • The official `mongodb-org` package will be used for installation, which is maintained and supported by MongoDB Inc.

1. Import the Public Key

First, install `gnupg` and `curl` if they're not already available:

sudo apt-get install gnupg curl

Then, import the MongoDB public GPG key:

curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
   --dearmor

2. Create a List File for MongoDB

Create the list file `/etc/apt/sources.list.d/mongodb-org-7.0.list` for your version of Ubuntu:

For Ubuntu 22.04 (Jammy):
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
For Ubuntu 20.04 (Focal):
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

3. Reload Local Package Database

Update the local package database:

sudo apt-get update

4. Install MongoDB Packages

To install the latest stable version of MongoDB:

sudo apt-get install -y mongodb-org

To install a specific version (e.g., 7.0.14):

sudo apt-get install -y mongodb-org=7.0.14 mongodb-org-database=7.0.14 mongodb-org-server=7.0.14 mongodb-mongosh=7.0.14 mongodb-org-mongos=7.0.14 mongodb-org-tools=7.0.14

5. Run MongoDB Community Edition

Start the MongoDB service:

sudo systemctl start mongod

Verify that MongoDB has started successfully:

sudo systemctl status mongod

To enable MongoDB to start on system reboot:

sudo systemctl enable mongod

To begin using MongoDB, start a `mongosh` session:

mongosh

6. Uninstall MongoDB Community Edition

To completely remove MongoDB:

1. Stop the MongoDB service:
sudo service mongod stop
2. Remove the packages:
sudo apt-get purge "mongodb-org*"
3. Remove data directories:
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

7. Additional Information

By default, MongoDB binds to localhost (127.0.0.1). To allow remote connections, you need to modify the `bindIp` setting in the MongoDB configuration file (`/etc/mongod.conf`) or use the `--bind_ip` command-line option.

For more detailed information and advanced configuration options, please refer to the [official MongoDB documentation](https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/).

Facing issues? Have Questions? Post them here! I am happy to answer!







Author Info:

Rakesh (He/Him) has a Masters Degree in Computer Science with over 15+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap