MongoDB Installation

MongoDB Installation

Operating Systems for MongoDB Installation

You can run MongoDB on the following Operating Systems:

  • Linux
  • Debian
  • RHEL / CentOS 6, 7 and 8
  • macOS
  • Ubuntu
  • Windows Server

MongoDB on Linux: To run MongoDB, you can use Linux version 2.6.36 or later, with XFS or EXT4 file system. The performance of XFS is much better with MongoDB. 

MongoDB on Debian: MongoDB 4.2 support Debian 10 "Buster" & Debian 9 "Stretch". It only provides the package for 64-bit builds of this release.

MongoDB with macOS: MongoDB 4.2 or updated released support macOS version 10 on Intel x86-64.

MongoDB on Ubuntu: MongoDB is already added to the Ubuntu package. It uses Ubuntu version 16.04.

MongoDB on Windows: MongoDB can be installed in both 32-bit and 64-bit format by the installers. The difference between the two installers is that 32-bit is appropriate for test environment and 64-bit for the production environment.

MongoDB installation on Windows

First of all, you have to download the latest version of MongoDB.

Steps for downloading MongoDB in Windows:

  • Open your favorite browser and go to the below link to download MongoDB:

https://www.mongodb.com/download-center/community

downloading MongoDB in Windows

Various variants of downloading are available like Solaris, Mac ios, Windows, Linux. Here, select the latest version or the version that your system supports. Windows version can be known by the execution of the following command:

C:\ wmic os get osarchitecture 

  • After choosing the version and operating system, click on the download button. Once downloaded, save it as MSI file wherever you want.
choosing the version and operating system
  • When the downloading is complete open the MSI file. In the start up screen click on the Next button.
start up screen click on the Next button
  • Accept the terms and conditions and click on next.
  • To install all the components, click on the Complete button, but if you want some selective components then select custom option.
if you want some selective components then select custom option.
  • Click next after selecting "Run service as network service user". Note the data directory as it will be needed afterward.
  • Hit the Install button to let the installation begin.
Hit the Install button to let the installation begin
  • Click on the Next button once the installation is completed.
(8)	Click on the Next button once the installation is completed.
  • Finally, click on the Finish button to let the installation complete.
click on the Finish button

Steps for Setting up MongoDB environment

  • MongoDB is installed in the following path:
C://programfiles/mongodb/server/version/bin

Inside the bin, we can see several files where the main two files are mongo.exe and mongod.exe. mongo.exe is the command-line shell to work with the database, and mongod.exe runs in the background.

  • First time when we execute
C:\mongodb\bin\mongod.exe  

You find an error message that c:\data\db not found as MongoDB demands data folder to store the databases. Create a new folder named as data in the C drive of your computer by using explorer. Create another folder called db inside this data folder.

The default path will be:

C:\data\db
  • Now execute mongod.exe again on command prompt and allow access, we see that it is ready and waiting for the connection.
  • Now we open one more terminal to execute mongo.exe.
C:\mongodb\bin\mongo.exe  

You can see that the connection is accepted.

For testing, we write db on the command prompt and can see the sample database.