How to Install MongoDB 4.4 on Linux Mint 20 Ulyana

5596
Share:
how-to-install-mongodb-4-4-on-linux-mint-20-ulyana

MongoDB is an open source database that uses a document-oriented data model. Unlike relational databases, it doesn't consist of tables and rows, but it’s built on an architecture of collections and documents. Documents comprise sets of key-value pairs and are the basic unit of data in it. Collections contain sets of documents and function as the equivalent of relational database tables.

There are two editions of MongoDB available to the customers – the Community and Enterprise version. Now, for general users, the MongoDB Community edition will be enough for testing/developing purposes. However, for large-scale implementation, it’s a good idea to get the Enterprise one. MongoDB Enterprise comes with additional features like customer support, Kubernetes integration, faster memory performance, certification, etc.

In this guide, we'll cover the Community version.

MongoDB Features

  • Easy installation and configuration.
  • Auto-sharding: data can be distributed to different machines accessible to application and if one server cannot handle the data, the rest will, thus preventing failure and improving read/write operations.
  • Schemaless database system hence provides the ability to use different data types. Your code defines your schema.
  • Fast query response.
  • Replication and gridFS. Easy to set up high availability to increase performance.
  • Highly scalable. Data can be distributed to several machines to handle big data.

MongoDB Installation On Linux Mint 20 Ulyana

MongoDB 4.4 Installation Using MongoDB Repository

Linux Mint, being an Ubuntu derivative, can directly grab MongoDB from the package server. Although Ubuntu has its own official MongoDB package, there are chances that we need to install more updated version. As the time of this writing, the latest version of MongoDB available is 4.4. Follow these steps to install MongoDB Community Edition package on Linux Mint 20 (Ulyana, Ulyssa):

  1. Import the public key used by the package management system.
    The Ubuntu package management tools (i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys. Issue the following command to import the MongoDB public GPG key:
    $ wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
  2. Create a list file for MongoDB.
    Create the /etc/apt/sources.list.d/mongodb-org-4.4.list list file using the command appropriate version of Ubuntu. Because Linux Mint 20 Ulyana is derived from Ubuntu 20.04 Focal Fossa, we'll use focal here:
    $ echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee 
    /etc/apt/sources.list.d/mongodb-org-4.4.list
  3. Reload local package database.
    Issue the following command to reload the local package database:
    $ sudo apt update
    Update system package

  4. Install the MongoDB packages.
    To install the latest stable version of MongoDB, issue the following command:
    $ sudo apt install -y mongodb-org
    Apt install mongodb-org

  5. Start MongoDB.
    Issue the following command to start mongod:
    $ sudo systemctl start mongod
  6. Verify that MongoDB has started successfully.
    Next step is to verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading
    [initandlisten] waiting for connections on port 
    where <port> is the port configured in /etc/mongod.conf, 27017 by default.

  7. Enjoy. Now you have a working installation of MongoDB 4.4 on your Linux Mint 20 (Ulyana, Ulyssa).

MongoDB Installation Using Ubuntu's Repository

Using official Ubuntu's repository is easier if you don't care if you're using older MongoDB version.

First, make sure your packages are up-to-date. Open up a terminal and type:

$ sudo apt update && sudo apt upgrade -y

Go ahead and install MongoDB with:

$ sudo apt install mongodb

That’s it! MongoDB is now installed on your machine.

The MongoDB service should automatically be started on install, but to check the status type

$ sudo systemctl status mongodb

You can see that the service is active.

Running MongoDB

MongoDB is currently a systemd service, so we’ll use systemctl to check and modify it’s state, using the following commands:

$ sudo systemctl status mongodb
$ sudo systemctl stop mongodb
$ sudo systemctl start mongodb
$ sudo systemctl restart mongodb

You can also change if MongoDB automatically starts when the system starts up (default: enabled):

$ sudo systemctl disable mongodb
$ sudo systemctl enable mongodb

To start working with (creating and editing) databases, type:

$ mongo

This will start up the mongo shell. Please check out the manual for detailed information on the available queries and options.

Uninstall MongoDB

If you installed MongoDB from the Ubuntu Repository and want to uninstall it (maybe to install using the officially supported way), type:

$ sudo systemctl stop mongodb
$ sudo apt purge mongodb
$ sudo apt autoremove

This should completely get rid of your MongoDB install. Make sure to backup any collections or documents you might want to keep since they will be wiped out!

Final Words

Well, that's it. I hope that you now know how to install MongoDB 4.4 on Linux Mint 20 (20 Ulyana, 20.1 Ulyssa). If you run into any issues or have any feedback feel free to drop a comment below.

Tags Linux
Share:

0 comment

Leave a reply

Your email address will not be published. Required fields are marked *