In this guide, we are going to look at how to install MongoDB 4.4 on Oracle Linux 8. MongoDB is a document-oriented NoSQL database preferred for high volume data storage. Unlike the traditional databases that uses relational databases, MongoDB uses collection of documents. The documents have key-value pairs which are the basic units of data in MongoDB. The collections also have set of documents and functions equating to the relational databases tables. MongoDB offers both a Community and an Enterprise version of the database:

  • MongoDB Community: The available and free to use edition of MongoDB
  • MongoDB Enterprise: This is available as part of the MongoDB Enterprise Advanced subscription and comes with comprehensive support for MongoDB deployment. It includes features such as LDAP and Kerberos support, on-disk encryption, and auditing.

In this guide, we are going to look at the installation on MongoDB 4.4 Community Edition on Oracle Linux 8.

What are the features of MongoDB?

The following are some of the important features of MongoDB that would make you want to use MongoDB.

  • Indexing – you can index any field in the document
  • Replication – supports master slave replication
  • Support ad hoc queries – In MongoDB, you can search by field, range query and it also supports regular expression searches.
  • Load balancing – It has an automatic load balancing configuration because of data placed in shards.
  • Data duplication – MongoDB can run over multiple servers. The data is duplicated to keep the system up and also keep its running condition in case of hardware failure.
  • Supports map reduce and aggregation tools.
  • Uses JavaScript instead of Procedures.
  • It is a schema-less database written in C++.
  • Provides high performance.
  • Stores files of any size easily without complicating your stack.
  • Easy to administer in the case of failures.
  • Supports JSON data model with dynamic schemas, Auto-sharding for horizontal scalability and Built in replication for high availability.

Install MongoDB 4.4 on Oracle Linux 8

Use the following steps to install MongoDB 4.4 on Oracle Linux 8. MongoDB packages are available in the official project provided repositories. This will be added to the system prior to the installation of MongoDB 4.4 on Oracle Linux 8.

Step 1: Update your system packages

Always start by ensuring your system is up to date before installations.

sudo dnf -y update

Step 2: Add MongoDB 4.4 repository

We are going to create a file /etc/yum.repos.d/mongodb-org-4.4.repo so that we can install MongoDB 4.4 directly using yum

Add the following content and save the repository file.

sudo tee /etc/yum.repos.d/mongodb-org-4.4.repo<<EOF
name=MongoDB Repository 

Step 3: Install MongoDB packages

Having added repository, we will go ahead to install the latest version of MongDB using the below command:

sudo dnf install -y mongodb-org

To install a specific release of MongoDB, you need to specify each component with the version as shown:

sudo dnf install -y mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools

Note that you can specify any version to install. Yum, however, upgrades the packages whenever there is a new version. To prevent this upgrade, pin the packages by editing /etc/yum.conf file. Add the below line to pin MongoDB packages.

$ exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

Step 4: Run MongoDB community edition on Oracle Linux 8

The next steps discuss the necessary prerequisites for running MongoDB 4.4


Unix-like operating systems mostly limit the resources a process can have and this could affect the functionality of MongoDB. This should be adjusted accordingly. A ulimit value below 64000 will not work for MingoDB 4.4

Directory Paths

By default, MongoDB uses the below directories with the user mongod

  • /var/lib/mongo (the data directory)
  • /var/log/mongodb (the log directory)

Note that if you installed MongoDB using repository, the directories will be created alongside the user mongod. However, if you installed through downloading tarballs, the directory will not be created and you will need to manually create them.

Create MongoDB directories

Run the below commands if you need to manually create MongoDB directories.

sudo mkdir -p /var/lib/mongo
sudo mkdir -p /var/log/mongodb

Set the owner and group of these directories to mongod user.

sudo chown -R mongod:mongod <directory>

Use Custom Directories for MongoDB

To use other directory other that the default MongoDB directory, we will first create the directory then edit mongodb.conf file and modify the path parameters.

$ sudo mkdir /some/data/directory
$ sudo mkdir  /some/log/directory/mongod.log

Open /etc/mongodb.conf file and edit as shown then save.

sudo vim /etc/mongodb.conf

Look out for systemLog and storage parameters and update your new directories accordingly.

  dbPath /some/data/directory
  path  /some/log/directory/mongod.log

Ensure that mongod user has access to the created directories

$ sudo chown -R mongod:mongod <directory>

Step 5: Configure SElinux

SElinux policy prevents MongoDB from accessing /sys/fs/cgroup, required for determining the available memory on your system. To run Selinux in enforcing mode, we need to adjust SElinux policy with the following steps:

Ensure the system has checkpolicy package installed.

$ sudo dnf install checkpolicy

Next Create a custom policy file mongodb_cgroup_memory.te:

cat > mongodb_cgroup_memory.te <<EOF
module mongodb_cgroup_memory 1.0;
    require {
    type cgroup_t;
    type mongod_t;
    class dir search;
    class file { getattr open read };
#============= mongod_t ==============
allow mongod_t cgroup_t:dir search;
allow mongod_t cgroup_t:file { getattr open read };

Now compile and load the custom policy module using the below commands:

checkmodule -M -m -o mongodb_cgroup_memory.mod mongodb_cgroup_memory.te
semodule_package -o mongodb_cgroup_memory.pp -m mongodb_cgroup_memory.mod
sudo semodule -i mongodb_cgroup_memory.pp

MongoDB is now able to access the required files with SElinux enforcing.

Non-Default MongoDB Directory Path(s)

Update the SELinux policy to allow the mongod service to use the new directory: Run the below command.

$ semanage fcontext -a -t <type> </some/MongoDB/directory.*>

where specify one of the following types as appropriate:

  • mongod_var_lib_t for data directory
  • mongod_log_t for log file directory
  • mongod_var_run_t for pid file directory

Update the SELinux user policy for the new directory:

$ chcon -Rv -u system_u -t <type> </some/MongoDB/directory>

where specify one of the following types as appropriate:

  • mongod_var_lib_t for data directory
  • mongod_log_t for log directory
  • mongod_var_run_t for pid file directory

Apply the updated SELinux policies to the directory:

$ restorecon -R -v </some/MongoDB/directory>

For non-default MongoDB ports, run the command:

$ semanage port -a -t mongod_port_t -p tcp <portnumber>

Step 6: Managing MongoDB on Oracle Linux 8

The following steps show how we can manage MongoDB 4.4 on Oracle Linux 8

Start, stop, restart and Enable MongoDB

Run the following commands to start, enable, stop and restart MongoDB

$ sudo systemctl start mongod
$ sudo systemctl enable mongod
$ sudo systemctl stop mongod
$ sudo systemctl restart mongod

If mongod fails to start, reload daemon and run the start command again

$ sudo systemctl daemon-reload
$ sudo systemctl start mongod

Check MongoDB status

To check if MongoDB is running, we use the command:

$ sudo systemctl status mongod

You should get an output as below if running

Begin using MongoDB

Start a mongo shell on the same host machine as the mongod


To find out the current database you are in, simply run the command db


To list databases, run the command:

show databases
admin 0.000G
config 0.000G
local 0.000G

To use a partcular database, use the command use

 use <db-name>

To create a new database, run the use command. In this case, since the database does not exist, it will be created.

use <new-db-name>

That’s it for now. You have successfully installed MongoDB 4.4 on Oracle Linux 8. Enjoy your usage and check below more interesting Linux guides.

Learning materials:


MongoDB: The Definitive Guide: Powerful and Scalable Data Storage

$36.17  in stock
10 new from $36.17
5 used from $37.98
Free shipping
Buy Now
as of December 3, 2020 5:31 am

Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems

$30.00  in stock
33 new from $30.00
18 used from $23.85
Free shipping
Buy Now
as of December 3, 2020 5:31 am

NoSQL with MongoDB in 24 Hours, Sams Teach Yourself

$22.17  in stock
13 new from $22.17
20 used from $15.40
Buy Now
as of December 3, 2020 5:31 am


in stock
in stock
in stock


Please enter your comment!
Please enter your name here

fourteen − four =