This section will cover steps for a Centos or RHEL environment as an example. For
more information on installing MongoDB on other Operating Systems, refer to the MongoDB
documentation here (Install MongoDB).
About this task
To install MongoDB on Linux, do the following:
Procedure
-
Create a repository file to use YUM to install MongoDB:
Using root:
> cd /etc/yum.repos.d
In /etc/yum.repos.d use VI to create the repository.
>vi mongodb-org-4.2.repo
And paste in the following contents:
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
After saving/exiting the file (:wq), execute YUM to install the MongoDB package.
>yum install mongodb-org
Note: When copying and pasting, ensure all characters are present (ie: the
"-" in the baseurl
).
Note: For more information on MongoDB documentation, click
Install MongoDB.
-
This will install the mongodb components, create the mongod user and default log and data directories. You can validate this by checking that the following two directories exist and are owned by ‘mongod'
/var/log/mongodb
/var/lib/mongo
To modify the default directories, consult the online documentation for MongoDB as referred to earlier.