{"id":1928,"date":"2024-11-13T07:51:44","date_gmt":"2024-11-13T07:51:44","guid":{"rendered":"https:\/\/www.vibidsoft.com\/blog\/?p=1928"},"modified":"2025-08-28T11:05:31","modified_gmt":"2025-08-28T11:05:31","slug":"how-to-install-mongodb-on-centos-a-step-by-step-guide","status":"publish","type":"post","link":"https:\/\/www.vibidsoft.com\/blog\/how-to-install-mongodb-on-centos-a-step-by-step-guide\/","title":{"rendered":"How to Install MongoDB on CentOS: A Step-by-Step Guide"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.mongodb.com\/\" target=\"_blank\" rel=\"noopener\" title=\"\">MongoDB<\/a>, a popular NoSQL database, is known for its high performance, scalability, and flexibility. Whether you are working on small-scale projects or enterprise-level applications, installing MongoDB on your CentOS server can help you manage your data seamlessly. This guide walks you through the installation process step-by-step to get MongoDB up and running on CentOS.<\/p>\n\n\n\n<h3>Prerequisites<\/h3>\n\n\n\n<p>Before starting, make sure you have:<\/p>\n\n\n\n<ul><li>A CentOS 7 or CentOS 8 system<\/li><li>A user account with sudo or root privileges<\/li><li>Access to the internet for downloading packages<\/li><\/ul>\n\n\n\n<h3>Step 1: Update Your System<\/h3>\n\n\n\n<p>Ensure that your CentOS system is up-to-date before installing MongoDB. Run the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum update -y\nsudo yum upgrade -y<\/code><\/pre>\n\n\n\n<h3>Step 2: Add the MongoDB Repository<\/h3>\n\n\n\n<p>MongoDB is not included in the default CentOS repositories, so you need to add the official MongoDB repository manually.<\/p>\n\n\n\n<ol><li>Create a <code>.repo<\/code> file in the <code>\/etc\/yum.repos.d\/<\/code> directory:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vi \/etc\/yum.repos.d\/mongodb-org-6.0.repo<\/code><\/pre>\n\n\n\n<ol start=\"2\"><li>Add the following content to the file:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;mongodb-org-6.0]\nname=MongoDB Repository\nbaseurl=https:\/\/repo.mongodb.org\/yum\/redhat\/$releasever\/mongodb-org\/6.0\/x86_64\/\ngpgcheck=1\nenabled=1\ngpgkey=https:\/\/www.mongodb.org\/static\/pgp\/server-6.0.asc<\/code><\/pre>\n\n\n\n<p>Save and close the file.<\/p>\n\n\n\n<h3>Step 3: Install MongoDB<\/h3>\n\n\n\n<p>Now, install MongoDB by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum install -y mongodb-org<\/code><\/pre>\n\n\n\n<p>This command installs the <code>mongodb-org<\/code> package, which includes:<\/p>\n\n\n\n<ul><li><code>mongodb-org-server<\/code> \u2013 the main MongoDB server<\/li><li><code>mongodb-org-mongos<\/code> \u2013 a routing service for sharded clusters<\/li><li><code>mongodb-org-shell<\/code> \u2013 the interactive MongoDB shell<\/li><li><code>mongodb-org-tools<\/code> \u2013 a collection of tools for database operations<\/li><\/ul>\n\n\n\n<h3>Step 4: Start and Enable MongoDB<\/h3>\n\n\n\n<p>After the installation is complete, start the MongoDB service and enable it to start on boot:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl start mongod\nsudo systemctl enable mongod<\/code><\/pre>\n\n\n\n<h3>Step 5: Verify the Installation<\/h3>\n\n\n\n<p>To ensure MongoDB is running properly, check its status with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status mongod<\/code><\/pre>\n\n\n\n<p>You should see an output indicating that MongoDB is active and running.<\/p>\n\n\n\n<h3>Step 6: Configure MongoDB (Optional)<\/h3>\n\n\n\n<p>By default, MongoDB listens on <code>localhost<\/code>. To allow remote connections, you need to modify the MongoDB configuration file:<\/p>\n\n\n\n<ol><li>Open the configuration file:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vi \/etc\/mongod.conf<\/code><\/pre>\n\n\n\n<ol start=\"2\"><li>Find the <code>bindIp<\/code> line and change it as needed:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code># network interfaces\nnet:\n  port: 27017\n  bindIp: 0.0.0.0<\/code><\/pre>\n\n\n\n<ol start=\"3\"><li>Save and close the file, then restart MongoDB to apply changes:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart mongod<\/code><\/pre>\n\n\n\n<h3>Step 7: Set Up Firewall Rules<\/h3>\n\n\n\n<p>If you need to access MongoDB from a remote location, you should open the necessary firewall port (default: 27017):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --zone=public --add-port=27017\/tcp --permanent\nsudo firewall-cmd --reload<\/code><\/pre>\n\n\n\n<h3>Conclusion<\/h3>\n\n\n\n<p>Congratulations! You have successfully installed and configured MongoDB on your CentOS system. MongoDB is now ready to support your data-driven applications with its powerful and flexible database architecture.<\/p>\n\n\n\n<p>Looking for professional support with database management or custom development solutions? <strong><a href=\"https:\/\/www.vibidsoft.com\/\">Vibidsoft Pvt Ltd<\/a><\/strong> has a team of experts ready to assist with MongoDB installations, optimization, and more. <a href=\"https:\/\/www.vibidsoft.com\/contact\" target=\"_blank\" rel=\"noopener\">Contact us<\/a> today to ensure your infrastructure is set up for success!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MongoDB, a popular NoSQL database, is known for its high performance, scalability, and flexibility. Whether you are working on small-scale projects or enterprise-level applications, installing MongoDB on your CentOS server can help you manage your data seamlessly. This guide walks&#8230; <a class=\"more-link\" href=\"https:\/\/www.vibidsoft.com\/blog\/how-to-install-mongodb-on-centos-a-step-by-step-guide\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":1929,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[452,2711],"tags":[2952,2957,2958,2951,2949,2953,2955,2956,2947,2959,2946,2954,2960,2950,2948],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.vibidsoft.com\/blog\/wp-json\/wp\/v2\/posts\/1928"}],"collection":[{"href":"https:\/\/www.vibidsoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vibidsoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vibidsoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vibidsoft.com\/blog\/wp-json\/wp\/v2\/comments?post=1928"}],"version-history":[{"count":2,"href":"https:\/\/www.vibidsoft.com\/blog\/wp-json\/wp\/v2\/posts\/1928\/revisions"}],"predecessor-version":[{"id":2762,"href":"https:\/\/www.vibidsoft.com\/blog\/wp-json\/wp\/v2\/posts\/1928\/revisions\/2762"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.vibidsoft.com\/blog\/wp-json\/wp\/v2\/media\/1929"}],"wp:attachment":[{"href":"https:\/\/www.vibidsoft.com\/blog\/wp-json\/wp\/v2\/media?parent=1928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vibidsoft.com\/blog\/wp-json\/wp\/v2\/categories?post=1928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vibidsoft.com\/blog\/wp-json\/wp\/v2\/tags?post=1928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}