{"id":1551,"date":"2024-12-22T07:44:48","date_gmt":"2024-12-22T07:44:48","guid":{"rendered":"https:\/\/hostingn.in\/tutorials\/?p=1551"},"modified":"2024-12-24T11:11:22","modified_gmt":"2024-12-24T11:11:22","slug":"installing-mongodb-on-ubuntu-in-2025","status":"publish","type":"post","link":"https:\/\/hostingn.in\/tutorials\/installing-mongodb-on-ubuntu-in-2025\/","title":{"rendered":"A Step-by-Step Guide: Installing MongoDB on Ubuntu in 2025 and Checking the Version"},"content":{"rendered":"<p><strong>Introduction to MongoDB<\/strong><\/p>\n<p>MongoDB is a popular, open-source, NoSQL <a href=\"https:\/\/hostingn.in\/tutorials\/creating-and-granting-privileges-in-mysql\/\">database management system<\/a> that has gained significant traction in recent years. As a document-oriented database, MongoDB offers a flexible and scalable solution for storing and managing data, making it a preferred choice for modern web applications, IoT projects, and big data initiatives.<\/p>\n<p>In this comprehensive guide, we will walk you through the process of installing <a href=\"https:\/\/hostingn.in\/tutorials\/install-mongodb-on-ubuntu\/\">MongoDB<\/a> on an Ubuntu system in 2025 and explore the steps to check the version of the installed MongoDB instance.<\/p>\n<h2>Why choose MongoDB for your database needs?<\/h2>\n<p>MongoDB&#8217;s unique features and capabilities make it a compelling choice for a wide range of applications. Some of the key reasons to consider MongoDB include:<\/p>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\"><strong>Flexible Data Model<\/strong>: MongoDB&#8217;s document-oriented data model allows for the storage of complex, semi-structured data without the need for rigid schemas, making it highly adaptable to evolving application requirements.<\/li>\n<li class=\"pb-1\"><strong>Scalability and High Availability<\/strong>: MongoDB&#8217;s distributed architecture and sharding capabilities enable seamless scaling to handle growing data volumes and user demands. It also provides built-in replication and automatic failover for high availability.<\/li>\n<li class=\"pb-1\"><strong>Query Flexibility<\/strong>: MongoDB&#8217;s rich query language, including support for aggregation, geospatial queries, and text search, allows for powerful and efficient data manipulation.<\/li>\n<li class=\"pb-1\"><strong>Performance Optimization<\/strong>: MongoDB&#8217;s use of indexes, caching, and other performance-enhancing features ensures fast data retrieval and processing, even for large datasets.<\/li>\n<li class=\"pb-1\"><strong>Ecosystem and Community Support<\/strong>: MongoDB benefits from a thriving ecosystem of tools, libraries, and community support, making it easier to integrate with various applications and frameworks.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/hostingn.in\/cloud-hosting\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1276\" src=\"https:\/\/hostingn.in\/tutorials\/wp-content\/uploads\/2024\/11\/www.hostingn.in-2-300x88.png\" loading=\"lazy\" alt=\"HostingN\" width=\"518\" height=\"152\" srcset=\"https:\/\/hostingn.in\/tutorials\/wp-content\/uploads\/2024\/11\/www.hostingn.in-2-300x88.png 300w, https:\/\/hostingn.in\/tutorials\/wp-content\/uploads\/2024\/11\/www.hostingn.in-2-768x225.png 768w, https:\/\/hostingn.in\/tutorials\/wp-content\/uploads\/2024\/11\/www.hostingn.in-2.png 1024w\" sizes=\"auto, (max-width: 518px) 100vw, 518px\" \/><\/a><\/p>\n<h2>Installing MongoDB on Ubuntu<\/h2>\n<h3>Step-by-step guide to installing MongoDB on Ubuntu in 2025<\/h3>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\"><strong>Update the Package Lists<\/strong>: Begin by updating the package lists on your Ubuntu system:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\"><span class=\"token\">sudo<\/span> <span class=\"token\">apt-get<\/span> update\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\"><strong>Install the Required Dependencies<\/strong>: Install the necessary dependencies for MongoDB:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\"><span class=\"token\">sudo<\/span> <span class=\"token\">apt-get<\/span> <span class=\"token\">install<\/span> -y gnupg\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\"><strong>Import the MongoDB GPG Key<\/strong>: Import the official MongoDB GPG key to ensure the integrity of the MongoDB packages:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\"><span class=\"token\">wget<\/span> -qO - https:\/\/www.mongodb.org\/static\/pgp\/server-6.0.asc <span class=\"token\">|<\/span> <span class=\"token\">sudo<\/span> apt-key <span class=\"token\">add<\/span> -\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\"><strong>Create the MongoDB Repository<\/strong>: Create a MongoDB repository file to enable the installation of the latest MongoDB packages:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\"><span class=\"token\">echo<\/span> <span class=\"token\">\"deb [ arch=amd64,arm64 ] https:\/\/repo.mongodb.org\/apt\/ubuntu focal\/mongodb-org\/6.0 multiverse\"<\/span> <span class=\"token\">|<\/span> <span class=\"token\">sudo<\/span> <span class=\"token\">tee<\/span> \/etc\/apt\/sources.list.d\/mongodb-org-6.0.list\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\"><strong>Install MongoDB<\/strong>: Install the MongoDB package:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\"><span class=\"token\">sudo<\/span> <span class=\"token\">apt-get<\/span> <span class=\"token\">install<\/span> -y mongodb-org\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\"><strong>Start the MongoDB Service<\/strong>: Start the MongoDB service and enable it to start automatically on system boot:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\"><span class=\"token\">sudo<\/span> systemctl start mongod\r\n<span class=\"token\">sudo<\/span> systemctl <span class=\"token\">enable<\/span> mongod\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\"><strong>Verify the Installation<\/strong>: Verify that MongoDB has been installed correctly by checking the service status:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\"><span class=\"token\">sudo<\/span> systemctl status mongod\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<p>You should see the MongoDB service running and active.<\/p>\n<h2>Checking the version of MongoDB installed on Ubuntu<\/h2>\n<h3>How to check the MongoDB version using the command line<\/h3>\n<p>To check the version of MongoDB installed on your <a href=\"https:\/\/hostingn.in\/tutorials\/how-to-install-lamp-on-ubuntu\/\">Ubuntu<\/a> system using the command line, follow these steps:<\/p>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\">Open a terminal on your Ubuntu system.<\/li>\n<li class=\"pb-1\">Run the following command to display the MongoDB version:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\">mongod --version\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<p>This will output the version of the MongoDB server installed on your system.<\/p>\n<h3>How to check the MongoDB version using the MongoDB shell<\/h3>\n<p>Alternatively, you can check the MongoDB version using the MongoDB shell:<\/p>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\">Open the MongoDB shell by running the following command in your terminal:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\">mongo\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\">Once inside the MongoDB shell, run the following command to display the MongoDB version:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\">db.version<span class=\"token\">(<\/span><span class=\"token\">)<\/span>\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<p>This will output the version of the MongoDB server you have installed.<\/p>\n<h2>Troubleshooting common issues during installation and version checking<\/h2>\n<p>If you encounter any issues during the installation or version checking process, here are some steps you can take to troubleshoot:<\/p>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\"><strong>Check the MongoDB Service Status<\/strong>: Ensure that the MongoDB service is running correctly by checking its status using the following command:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\"><span class=\"token\">sudo<\/span> systemctl status mongod\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<p>If the service is not running, try starting it using the following command:<\/p>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\"><span class=\"token\">sudo<\/span> systemctl start mongod\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\"><strong>Verify the MongoDB Repository Configuration<\/strong>: Double-check the MongoDB repository configuration file located at\u00a0<code>\/etc\/apt\/sources.list.d\/mongodb-org-6.0.list<\/code>. Ensure that the repository URL and distribution name (in this case,\u00a0<code>focal<\/code>) are correct.<\/li>\n<li class=\"pb-1\"><strong>Clear the APT Cache<\/strong>: If you&#8217;re still experiencing issues, try clearing the APT cache and updating the package lists:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\"><span class=\"token\">sudo<\/span> <span class=\"token\">apt-get<\/span> clean\r\n<span class=\"token\">sudo<\/span> <span class=\"token\">apt-get<\/span> update\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\"><strong>Check for Firewall Rules<\/strong>: Ensure that your firewall is not blocking the MongoDB port (default is 27017). You can check the firewall status and rules using the following commands:<\/li>\n<\/ol>\n<div class=\"relative font-sans rounded-t-md overflow-hidden\">\n<div class=\"flex justify-between bg-gray-800 py-1.5 px-4 text-gray-200\">\n<div class=\"text-xs lowercase\">bash<\/div>\n<\/div>\n<div class=\"overflow-x-auto transition-colors duration-200\">\n<pre><code class=\"language-bash\"><span class=\"token\">sudo<\/span> ufw status\r\n<span class=\"token\">sudo<\/span> ufw allow <span class=\"token\">27017<\/span>\/tcp\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<ol class=\"!whitespace-normal list-decimal ml-5\">\n<li class=\"pb-1\"><strong>Review the MongoDB Log Files<\/strong>: If you&#8217;re still unable to resolve the issue, check the MongoDB log files located at\u00a0<code>\/var\/log\/mongodb\/<\/code>\u00a0for any error messages or clues that may help you identify the problem.<\/li>\n<\/ol>\n<h2>Conclusion<\/h2>\n<p>In this article, we have provided a comprehensive guide on how to install MongoDB on an Ubuntu system in 2025 and how to check the version of the installed MongoDB instance. By following the step-by-step instructions, you should be able to successfully set up MongoDB on your Ubuntu system and verify its version using both the command line and the MongoDB shell.<\/p>\n<p>If you&#8217;re ready to take your database management to the next level with MongoDB, be sure to check out our [MongoDB Certification Training](https:\/\/www.example.com\/mongodb-certification-training) program. Our expert-led courses will help you master the latest MongoDB features and best practices, empowering you to build scalable and efficient data-driven applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction to MongoDB MongoDB is a popular, open-source, NoSQL database management system that has gained significant traction in recent years. As a document-oriented database, MongoDB&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1891,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[106],"tags":[153,209],"class_list":["post-1551","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","tag-mongodb","tag-mongodb-on-ubuntu"],"_links":{"self":[{"href":"https:\/\/hostingn.in\/tutorials\/wp-json\/wp\/v2\/posts\/1551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostingn.in\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostingn.in\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostingn.in\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hostingn.in\/tutorials\/wp-json\/wp\/v2\/comments?post=1551"}],"version-history":[{"count":4,"href":"https:\/\/hostingn.in\/tutorials\/wp-json\/wp\/v2\/posts\/1551\/revisions"}],"predecessor-version":[{"id":1907,"href":"https:\/\/hostingn.in\/tutorials\/wp-json\/wp\/v2\/posts\/1551\/revisions\/1907"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hostingn.in\/tutorials\/wp-json\/wp\/v2\/media\/1891"}],"wp:attachment":[{"href":"https:\/\/hostingn.in\/tutorials\/wp-json\/wp\/v2\/media?parent=1551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostingn.in\/tutorials\/wp-json\/wp\/v2\/categories?post=1551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostingn.in\/tutorials\/wp-json\/wp\/v2\/tags?post=1551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}