Install MongoDB(server, shell, compass) in ubuntu.
Table of contents
Hi folks, Here is the step-by-step procedure for the complete setup and installation of MongoDB in Ubuntu OS.
If you're here to learn about MongoDB installation, chances are you're already familiar. Nonetheless, let's briefly explore MongoDB's features and capabilities.
What is MongoDB?
MongoDB is a nonrelational database management system (DBMS) that uses flexible documents instead of tables and rows to process and store various forms of data.
MongoDB is a NoSQL database known for its document-oriented model, offering flexibility and scalability for modern applications. With JSON-like documents, it supports dynamic schemas and distributed architecture. Here you can find long-winded about what is MongoDB. Let's get into the installation procedure.
To set up MongoDB completely we need to install the Mongo server, mongo shell, and mongo-compass.
MongoDB Community Server
Visit the MongoDB community server page and select the current version, select the current version of your Ubuntu select the packages as server, and click on the download button to download the server.
After downloading, open your terminal redirect to the path(where your Debian package is installed), and use the below command to install the Debian package.
sudo dpkg -i mongodb-org-server_7.0.2_amd64.deb
(mongodb-org-server_7.0.2_amd64.deb) replace this with the filename that downloaded to your device.
To check whether it installed properly, run the below command in your terminal
sudo systemctl status mongod
After run the above command you can observe it is inactive. To activate the server run the below command.
sudo systemctl start mongod
after completion of this, we need to install Mongoshell.
MongoDB shell
MongoDB shell is a Command Line Interface(CLI) that allows developers to interact with MongoDB using commands through the terminal.
After installing the community server we should install a shell to talk to the database using the text commands. so let's get into it.
Click here to download the MongoDB Shell select the latest version and also select the version of your Ubuntu and hit the download button to download the Debian (.dep) package.
After downloading, repeat the same process of redirecting to the path where the shell has downloaded and run the below command to install.
sudo dpkg -i mongodb-mongosh_2.0.1_amd64.deb
Here it is the shell is installed properly and if you want to make it confirm, run
mongosh
the terminal shows the Command Line Interface like test > like this.Here some default databases will be created automatically if you want to view the databases run this command
show dbs
then it will show admin, config, and local.Now you can do operations with MongoDB using the text commands.
Here we have almost completed the setup of MongoDB. And here is the important part that is mongo-compass.
MongoDB Compass
MongoDB Compass is a powerful GUI for querying, aggregating, and analyzing your MongoDB data in a visual environment.
Compass is free to use and source available, and can be run on macOS, Windows, and Linux.
Here is the link to download the MongoDB Compass and repeat the same steps to complete the installation process.
Here you are..! Now you can use MongoDB easily for data visualization and operations.
Subscribe to my newsletter
Read articles from Laxmanrao Balla directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Laxmanrao Balla
Laxmanrao Balla
I'm Laxman, a Frontend Developer dedicated to crafting clean, efficient, and captivating user interfaces with the latest and most reliable technologies. With 1.5 years of dedicated experience in frontend development, I specialize in JavaScript, React.js, Next.js, and TailwindCSS. I am committed to transforming innovative ideas into functional and intuitive digital experiences.