Linux

How to: install MongoDB on Linux Mint

22nd February 2018 — by That IT Guy0

main

Linux

How to: install MongoDB on Linux Mint

22nd February 2018 — by That IT Guy0

UPDATE – MINT 19: As of Mint 19, MongoDB is included in the official repositories and can be installed simply by running “sudo apt install mongodb“. Only follow this guide if you’re still using Mint 18.3 or under // Ubuntu 17.10 or under.

MongoDB is an open source database that uses a document-oriented data model. It’s one of several database types to arise in the mid-2000s under the NoSQL banner. Instead of using tables and rows as in relational databases, 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.

MongoDB does not come with a native installer for Linux Mint and requires a command line installation. To install it, follow these steps:

Step 1: Open the Command-line terminal and import the public GPG key. Just run the following commands.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

Step 2: Next, we’ll create the “/etc/apt/sources.list.d/mongodb-org-3.4.list” list file.

echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

Step 3: Run the system update

sudo apt-get update

Step 4: Install the latest stable version. This command will install all the related packages.

sudo apt-get install -y mongodb-org

Step 5: After installation, create a directory with name “data” and sub-directory with name “db” inside you home directory (change “yourusername” for your actual username directory). Otherwise, you may have issues starting MongoDB.

cd /home/yourusername
sudo mkdir -p data/db

Step 6: Give the directory “/data” enough permission

sudo chmod -R 775 data

Step 7: Create a configuration file with name “mongodb.service” to setup unit file.

sudo touch /etc/systemd/system/mongodb.service

Step : Open the above created file, paste the following lines of codes inside the editor and save the file

sudo nano /etc/systemd/system/mongodb.service
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

Step 9: You can now start the server.

sudo service mongodb start

Step 10: You can check the running status of the server with the following command.

sudo service mongodb status

That’s it, you’re done!

mongodb