How to install MongoDB 4.2 on Linux Mint 19


Update 23-12-2020: MongoDB 4.4 installation on Linux Mint 20 Ulyana available here.

Installing MongoDB on Ubuntu based Distributions

  1. Install MongoDB using Ubuntu’s repository.
  2. Install MongoDB using its official repository.

Install MongoDB 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!

Install MongoDB Using MongoDB's Repository

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.2. Follow these steps to install MongoDB Community Edition package on Linux Mint 19 (Tara, Tessa, Tina):

  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 - | sudo apt-key add -

  2. Create a list file for MongoDB.
    Create the /etc/apt/sources.list.d/mongodb-org-3.6.list list file using the command appropriate for your version of Ubuntu:
    $ echo "deb [ arch=amd64 ] bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

  3. Reload local package database.
    Issue the following command to reload the local package database:
    $ sudo apt-get update

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

  5. Start MongoDB.
    Issue the following command to start mongod:
    $ sudo service mongod start

  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 <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.2 on your Linux Mint 19.

Final Words

Well, that's it. I hope that you now know how to install MongoDB 4.2 on Linux Mint 19 (19 Tara, 19.1 Tessa, 19.2 Tina). If you run into any issues or have any feedback feel free to drop a comment below.

Tags Linux

1 comment

Leave a reply

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