How to install MongoDB 4.2 on Linux Mint 19
Installing MongoDB on Ubuntu based Distributions
- Install MongoDB using Ubuntu’s repository.
- 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.
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:
This will start up the mongo shell. Please check out the manual for detailed information on the available queries and options.
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):
- 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.2.asc | sudo apt-key add -
- Create a list file for MongoDB.
/etc/apt/sources.list.d/mongodb-org-3.6.listlist file using the command appropriate for your version of Ubuntu:
$ echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
- Reload local package database.
Issue the following command to reload the local package database:
$ sudo apt-get update
- Install the MongoDB packages.
To install the latest stable version of MongoDB, issue the following command:
$ sudo apt-get install -y mongodb-org
- Start MongoDB.
Issue the following command to start
$ sudo service mongod start
- Verify that MongoDB has started successfully.
Next step is to verify that the
mongodprocess has started successfully by checking the contents of the log file at
/var/log/mongodb/mongod.logfor a line reading
[initandlisten] waiting for connections on port <port>
<port>is the port configured in
- Enjoy. Now you have a working installation of MongoDB 4.2 on your Linux Mint 19.
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.