Installing MongoDB on Windows and Linux

Welcome to a tutorial on MongoDB. Here, we will take you through how you will set up and install MongoDB on your local machines, as well as other related tools on Windows operating systems and Linux operating systems.

 

Installing MongoDB on Windows

Let’s start with installing MongoDB on a Windows machine. It is quite easy to install MongoDB, just follow the steps below.

Step 1: Download MongoDB executable .msi file from the site MongoDB Download Centre. Then, select the latest version for Windows. The Windows Server 2008 R2 is the version for Windows 7, 8, or 10 users.

Installing MongoDB on Windows

Step 2: Double-click the downloaded .msi file to start the installation. Then select the option Custom during the installation process, to specify a custom location where you wish to install MongoDB. However, by default, it is installed in the C:mongodb directory.

 

Step 3: Now, once the installation is successful, the below directory structure is created. Just as shown below, we have installed our MongoDB in D:javamongodb

Installing MongoDB on Windows

Step 4: Next, navigate to the bin directory of MongoDB to understand the components used in MongoDB. The table below shows some important components and files to run.

 

Component.exe File
Servermongod.exe
Routermongos.exe
Clientmongo.exe

Step 5: Know what is necessary to set up the MongoDB environment. Although, MongoDB stores all its data under the folder datadb. Thus, it is advisable to create this directory under the folder where MongoDB is installed. Now, we will create a folder named data and one more folder named db inside the data folder. This is shown below.

Installing MongoDB on Windows

Step 6: Create a log folder to log the MongoDB data transactions. Now, under the log folder, create a log file FILE_NAME.log.

 

Step 7: To verify if the installation is successful or not, open the command prompt and navigate to the bin directory of the MongoDB installed folder.

 

Step 8: Now, execute the command mongod.exe --dbpath "DATA_DIRECTORY_PATH" to configure the data path and start the MongoDB server. Then, replace the DATA_DIRECTORY_PATH with the path of the data directory present inside the MongoDB installed folder. Now, on running this command, the below log will be displayed saying that the MongoDB configuration is successful and the server is up and running fine.

Installing MongoDB on Windows

 

Step 9: Open another command prompt window and navigate to the bin directory of MongoDB again, then start the MongoDB client in order to use the database system. Then run the command mongo in Command Prompt and it will get connected to the MongoDB where the default database is tested.

Installing MongoDB on Windows

 

Step 10: Finally, we have installed MongoDB on the windows environment successfully, and we are good to start with MongoDB.