w3resource

Install MongoDB on Linux

Download

MongoDB installation packages are available for both 32 bit and 64 bit Linux. You can download it, and install.

Here is the link to download the installation packages of MongoDB : http://www.mongodb.org/downloads

mongodb download Linux

Unzip

After downloading the zip file, unzip it to the folder where you want to install.

Create a data directory

MongoDB stores data in db folder within data folder. But, since this data folder is not created automatically, you have to create it manually. Remember that data directory should be created in the root (/).

mongodb installation Linux

Run the MongoDB server from command prompt

To run MongoDB server from command prompt, you have to execute mongod.exe file from bin folder of mongodb folder.

mongodb run Linux command

Getting started with administrative shell

To start administrative shell, enter bin directory of your MongoDB installation and execute mongo.exe file. The default administrative shell of MongoDB is a JavaScript shell. When you connect MongoDB immediately after installation, it connects to the test document (database).

run mongo shell

Since it is a JavaScript Shell, you can run some simple arithmetic operation.

db command will show you the list of documents(databases).

run mongo shell linux2

We will insert a simple record and retrieve the data now.

mongo first find linux

The first command inserts 8 to the z field, to the w3r collection(table).

MongoDB web interface

At a port number 1000 more than the port on which the MongoDB server is running, you can access a web interface of MongoDB.

If MongoDB is running at the default port 27017, the you can access the web interface at 28017.

mongodb web interface

Previous: Install MongoDB on Windows
Next: Introduction to mongo Shell



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/mongodb/installation-Linux.php