Install MongoDB in Ubuntu

MongoDB is a popular implementation is not a relational database. In a nutshell the database are of several types. Relational database type, most popular, store data in records of a table which consists of columns and rows. MongoDB belongs to the object-oriented type. The main difference of this type is that the work and the data is stored with the objects, in the same way as is done in popular objectively-oriented programming languages (C++, Java).

Relational databases are typically used for data that are important to safety and maximum reliability. Object-oriented databases faster but less reliable and are often used to store different events and statistical data. In this tutorial I will tell you how to install MongoDB Ubuntu 18.04.

  • Install MongoDB
    • 1. Installation from the distribution’s repository
    • 1. Installing from the repository developers
  • Removing MongoDB

Install MongoDB

1. Installation from the distribution’s repository

In modern distributions, the utility added to the official repository of the modern versions of Ubuntu. To install it just type in:

sudo apt install mongodb-server

You can then view the status of the service:

sudo systemctl status mongod

And add it in startup if you need it:

sudo systemctl enable mongod

To work with the database through the command line client mongo. For example, let’s look at the database version:

mongo

version()
quit()

If you are going to remove MongoDB, then please note that this database may already be used in any application, so first make sure that removing it, you won’t break anything.

1. Installing from the repository developers

If you want to get the latest version of the program, you need to install it from the repository, developers MongoDB. Before you install this version, it is necessary to remove the version from the official repositories, if it was installed:

sudo apt purge mongodb*

Next you need to integrate public key to the system is passed a package, to do this, type in terminal:

wget-qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -

Using the following command builds the file list of the package:

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

Update the database local packages:

 sudo apt update

And you can proceed to install:

 sudo apt install-y mongodb-org

Next you need to start the service mongod and add it to the startup:

sudo systemctl start mongod

sudo systemctl enable mongod

sudo systemctl status mongod

Then look at the version:

If something is not working the logs of the service, you can see in the folder /var/log/mongodb database files, /var/lib/mongodb

Removing MongoDB

To remove MongoDB from the computer, type:

 sudo apt purge mongodb-org*

Or if you installed the software from the official repositories, use:

sudo apt purge mongodb*

Now you know how to install MongoDB Ubuntu 18.04 on your computer and how to check which version you have installed and whether it works at all this database.

Source: losst.ru

(Visited 9 times, 1 visits today)