Announcement

Collapse
No announcement yet.

How to Install MongoDB on Ubuntu 24.04

Collapse
X
Collapse
  •  

  • How to Install MongoDB on Ubuntu 24.04


    When it comes to databases, you can have either relational or non-relational databases. Relational databases follow the SQL syntax, and their data is stored in structured tables. Examples of such databases are MySQL. However, non-relational databases store data in other formats, such as graphs, documents, etc., and a good example is MongoDB.

    MongoDB is a non-relational database that stores data as documents. The database is open-source, and by adding its repository to your source list, you will manage to install it on your Ubuntu 24.04. This post walks you through every required step.

    MongoDB Installation Guide on Ubuntu 24.04

    There are numerous reasons to choose MongoDB over other databases. For instance, if you want to achieve scalability and flexibility, MongoDB is the ideal non-relational database. Besides, MongoDB accommodates 32 and 64-bit systems.

    To install MongoDB, use the following steps.

    Step 1: Update the Repository

    When installing MongoDB, the recommended approach is to get its latest version by adding the MongoDB repository to your source list. Thus, we must first refresh the package index by updating it.

    $ sudo apt update




    Step 2: Install Dependency Packages

    Before we install MongoDB, a few packages need to be available on our Ubuntu 24.04. Some of them are already installed but you should run the below command to handle these dependency packages.

    $ sudo apt install gnupg wget apt-transport-https ca-certificates software-properties-common




    Step 3: Import MongoDB’s GPG Key

    When installing packages from a third-party repository, you should import a GPG key to verify the authenticity of the packages to ensure no harm comes to your system. For the MongoDB repository, we will import the below GPG key.

    $ wget -qO- https://pgp.mongodb.com/server-7.0.asc | gpg --dearmor | sudo tee /usr/share/keyrings/mongodb-server-7.0.gpg >/dev/null




    Step 4: Add MongoDB’s Repository

    The next step is to add the MongoDB repository for your Ubuntu Noble Numbat. We’ve used the echo command to add the repository to our source list. The lsb_release -cs will fetch the codename for Ubuntu 24.04 and use it to fetch the respective MongoDB repository.

    $ echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/7.0 multiverse" | sudo tee -a /etc/apt/sources.list.d/mongodb-org-7.0.list




    Again, update your repository to refresh the newly added repository.

    $ sudo apt update


    Step 5: Install MongoDB

    With the MongoDB repository on our system, we can now install MongoDB using the following command.

    $ sudo apt install mongodb-org




    Step 6: Enable and Start the MongoDB Service

    After installing MongoDB, we still need to enable it and check to ensure that it is active and running. We will reference the mongod.service with the following commands.

    $ sudo systemctl enable mongod.service

    $ sudo systemctl status mongod.service




    Step 7: Test the MongoDB Connection

    We’ve installed MongoDB on our system, but we need to test the connection to ensure everything checks out. An excellent way is by running a connection status using the mongosh shell tool. If the connection to the database can be established, we will get an ‘OK’ return status.

    $ mongosh --eval 'db.runCommand({ connectionStatus: 1 })’




    Step 8: Configure MongoDB for Better Security

    MongoDB has basic configurations that work okay for basic usage. However, it’s advisable to edit the security section of its configuration file, especially if using it in a production environment. Open your MongoDB’s config file using a text editor and edit the security section to have it as in the image below.



    Save the file, exit the text editor, and restart the MongoDB service.

    $ sudo systemctl restart mongod.service




    Step 9: Create an Admin User

    As part of enhancing your database security, you need to create an administrative user. To do so, access the MongoDB shell with the below command and select which database you want to use.

    $ mongosh

    $ use admin




    Next, create an admin user for your database and set their password and username. Moreover, set their roles, and lastly, quit the shell to close it.



    To verify that your admin user was successfully created, log in to your MongoDB using their username and the assigned password.

    $ mongosh -u username -p




    Once you enter your password, you should gain access to MongoDB. The last step is to select the admin database and display the available users.



    The output should confirm that your admin user exists.

    That’s how to install MongoDB on Ubuntu 24.04.

    Conclusion

    MongoDB is a preferred non-relational database for developers working on scalable projects. To install MongoDB, add its repository to your source list, then install it using APT. Next, configure the database and set your admin user. We’ve discussed what steps you should follow and give practical examples.





    More...
      Posting comments is disabled.

    Categories

    Collapse

    Article Tags

    Collapse

    There are no tags yet.

    Latest Articles

    Collapse

    • Using MAXQDA for Qualitative Data Analysis on Linux
      by Kasimba



      by George Whittaker


      Introduction

      Qualitative data analysis (QDA) is a cornerstone of research across various fields, from social sciences to marketing. It involves uncovering patterns, themes, and meanings within non-numerical data such as interviews, focus groups, and textual narratives. In this era of digital tools, MAXQDA stands out as a premier software solution for QDA, empowering researchers to organize...
      11-21-2024, 11:31 PM
    • HAProxy on Ubuntu: Load Balancing and Failover for Resilient Infrastructure
      by Kasimba



      by german.suarez


      Introduction

      In today’s fast-paced digital landscape, ensuring the availability and performance of applications is paramount. Modern infrastructures require robust solutions to distribute traffic efficiently and maintain service availability even in the face of server failures. Enter HAProxy, the de facto standard for high-performance load balancing and failover.


      This article...
      11-21-2024, 03:00 PM
    • Providing a license for package sources
      by Kasimba
      Arch Linux hasn't had a license for any package sources (such as PKGBUILD files) in the past, which is potentially problematic. Providing a license will preempt that uncertainty.

      In RFC 40 we agreed to change all package sources to be licensed under the very liberal 0BSD license. This change will not limit what you can do with package sources. Check out the RFC for more on the rationale and prior discussion.

      Before we make this change, we will provide contributors with...
      11-19-2024, 09:21 AM
    • Linux Binary Analysis for Reverse Engineering and Vulnerability Discovery
      by Kasimba



      by George Whittaker


      Introduction

      In the world of cybersecurity and software development, binary analysis holds a unique place. It is the art of examining compiled programs to understand their functionality, identify vulnerabilities, or debug issues—without access to the original source code. For Linux, which dominates servers, embedded systems, and even personal computing, the skill of binary analysis is...
      11-18-2024, 07:10 PM
    • Ubuntu vs Debian: Linux Distributions Compared Deep Dive
      by Kasimba
      Debian and Ubuntu are two popular Linux distributions. In this deep dive we will guide you on the key differences between them from perspective of both corporate enterprise and personal productivity or pleasure usage. After reading this blog post you should be in a better position to decide to select Ubuntu or Debian.
      Stewardship, Licensing, Community and Cost

      Where as Debian is 100% fully committed to free software as defined by the Debian Free Software Guidelines, Ubuntu is created...
      11-17-2024, 08:30 PM
    • Debian Backup and Recovery Solutions: Safeguard Your Data with Confidence
      by Kasimba



      by George Whittaker


      Introduction

      In the digital age, data loss is a critical concern, and effective backup and recovery systems are vital for any Debian system administrator or user. Debian, known for its stability and suitability in enterprise, server, and personal computing environments, offers a multitude of tools for creating robust backup and recovery solutions. This guide will explore these solutions,...
      11-13-2024, 05:30 PM
    Working...
    X