{"id":29960,"date":"2019-08-22T10:44:27","date_gmt":"2019-08-22T15:44:27","guid":{"rendered":"https:\/\/www.rosehosting.com\/blog\/?p=29960"},"modified":"2022-06-03T03:33:33","modified_gmt":"2022-06-03T08:33:33","slug":"how-to-install-mongodb-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/","title":{"rendered":"How to Install MongoDB on Ubuntu 18.04"},"content":{"rendered":"<div id=\"bsf_rt_marker\"><\/div><p><img decoding=\"async\" class=\"alignnone size-full wp-image-31784\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/08\/how-to-install-mongodb-on-ubuntu18.04.jpg\" alt=\"\" width=\"742\" height=\"372\" srcset=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/08\/how-to-install-mongodb-on-ubuntu18.04.jpg 742w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/08\/how-to-install-mongodb-on-ubuntu18.04-150x75.jpg 150w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/08\/how-to-install-mongodb-on-ubuntu18.04-300x150.jpg 300w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><\/p>\n<p>In this article, we will show you how to install <a href=\"https:\/\/www.rosehosting.com\/mongodb-hosting.html\" target=\"_blank\" rel=\"noopener noreferrer\">MongoDB<\/a>, manage its services, and allow remote connections on an\u00a0<a href=\"https:\/\/www.rosehosting.com\/ubuntu-hosting.html\" target=\"_blank\" rel=\"noopener noreferrer\">Ubuntu 18.04 VPS<\/a>.<\/p>\n<p><img decoding=\"async\" class=\"alignright size-full wp-image-31785\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/08\/mongodb-setup-guide-usage-configuration-for-ubuntu18.04-vps.jpg\" alt=\"\" width=\"150\" height=\"150\" \/>MongoDB is an open-source database management system that belongs to a family of NoSQL. NoSQL is different from traditional table-based SQL databases (<a href=\"https:\/\/www.rosehosting.com\/mysql-hosting.html\" target=\"_blank\" rel=\"noopener noreferrer\">MySQL<\/a> and <a href=\"https:\/\/www.rosehosting.com\/postgresql-hosting.html\" target=\"_blank\" rel=\"noopener noreferrer\">PostgreSQL<\/a>) &#8211; the data is stored in flexible JSON-like documents with no pre-defined schema, which allows for large changes to be made to databases with no downtime. Let&#8217;s get started with the installation.<br \/>\n<!--more--><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fc8d1f8fd09\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fc8d1f8fd09\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#Step-1-Connect-to-your-Server\" >Step 1: Connect to your Server<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#Step-2-Installing-MongoDB\" >Step 2: Installing MongoDB<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#Step-3-Configuring-MongoDB\" >Step 3: Configuring MongoDB<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#Step-4-Creating-Administrative-MongoDB-User\" >Step 4: Creating Administrative MongoDB User<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#Step-5-Verifying-the-Administrative-Users-Access\" >Step 5: Verifying the Administrative User&#8217;s Access<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#Step-6-Allow-Remote-MongoDB-Access-in-the-Firewall\" >Step 6: Allow Remote MongoDB Access in the Firewall<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#Step-7-Connect-to-MongoDB\" >Step 7: Connect to MongoDB<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#Step-8-Uninstall-MongoDB\" >Step 8: Uninstall MongoDB<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Step-1-Connect-to-your-Server\"><\/span>Step 1: Connect to your Server<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before we begin, you need to connect to your server via SSH as the root user. To do this, use the following command:<\/p>\n<pre>ssh root@<span style=\"color: #ff0000;\">IP_Address<\/span> -p <span style=\"color: #ff0000;\">port_number<\/span><\/pre>\n<p>You will need to replace <span style=\"color: #ff0000;\">IP_Address<\/span> and <span style=\"color: #ff0000;\">port_number<\/span> with your actual server IP address and SSH port number. If you don&#8217;t have access to the root account, you can use an account with sudo privileges instead.<\/p>\n<p>Once logged in, make sure that your server is up-to-date by running the following commands:<\/p>\n<pre>sudo apt update\nsudo apt upgrade<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step-2-Installing-MongoDB\"><\/span>Step 2: Installing MongoDB<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Ubuntu official software package repositories come with version 3.6.3 of MongoDB, but in this article, we will install MongoDB\u00a04.0 which is the latest available version. However, you can always check if a new version of MongoDB is available on their official website.<\/p>\n<p>In order to install the MongoDB 4.0 Community Edition on Ubuntu, we need to import the public key used by the package management system. We can do that with the following command:<\/p>\n<pre>sudo apt-key adv --keyserver hkp:\/\/keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4<\/pre>\n<p>Since we have the key imported now, we can add the MongoDB repository with this next line:<\/p>\n<pre>sudo add-apt-repository 'deb [arch=amd64] https:\/\/repo.mongodb.org\/apt\/ubuntu bionic\/mongodb-org\/4.0 multiverse'<\/pre>\n<p>We then update the packages list:<\/p>\n<pre>sudo apt update<\/pre>\n<p>At this point, the repository is enabled and packages list is updated &#8211; we can now continue with installing the MongoDB CE package by entering the following command:<\/p>\n<pre>sudo apt install mongodb-org<\/pre>\n<p>The mongodb-org-server, mongodb-org-mongos, mongodb-org-shell and mongodb-org-tools packages will be installed on your system as a part of the mongodb-org package.<\/p>\n<p>The MongoDB 4.0 Community Edition is now installed on the server. We then need to start the MongoDB service and enable it to start on boot.<\/p>\n<pre>sudo systemctl start mongod\nsudo systemctl enable mongod<\/pre>\n<p>To verify the MongoDB installation, we can check the connection status by typing the command:<\/p>\n<pre>mongo --eval 'db.runCommand({ connectionStatus: 1 })'<\/pre>\n<p>You should have an output similar to this:<\/p>\n<pre>MongoDB shell version v4.0.6\nconnecting to: mongodb:\/\/127.0.0.1:27017\/?gssapiServiceName=mongodb\nImplicit session: session { \"id\" : UUID(\"c806e0e1-ab30-4d41-b882-026c09d2893f\") }\nMongoDB server version: 4.0.6\n{\n\"authInfo\" : {\n\"authenticatedUsers\" : [ ],\n\"authenticatedUserRoles\" : [ ]\n},\n\"ok\" : 1\n}\n<\/pre>\n<p>Congratulations, you have successfully installed MongoDB on your server. The next step will go over configuring your MongoDB server.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step-3-Configuring-MongoDB\"><\/span>Step 3: Configuring MongoDB<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>We can configure the MongoDB instance by modifying the <code>mongod.conf<\/code> file, located in <code>\/etc\/<\/code>. We&#8217;ll use Nano to edit the file, but you can use your preferred text editor if you like.<\/p>\n<pre>sudo nano \/etc\/mongod.conf<\/pre>\n<p>In order to allow remote connections and better secure MongoDB, we will make some changes in the configuration file. MongoDB by default listens for connections on port 27017 on localhost (IP 127.0.0.1) only. In order to allow a remote MongoDB connection, you need to add your server IP address to the MongoDB configuration file. This is shown as an example below:<\/p>\n<pre>bind_ip = 127.0.0.1, <span style=\"color: #ff0000;\">your_server_ip<\/span>\n#port = 27017\n\nsecurity:\nauthorization: enabled<\/pre>\n<p>We also included an authorization option that will regulate user access to MongoDB databases. If the authorization option is not enabled, then each user will have access to all the MongoDB databases and can perform any action, which is a security risk. After we save the changes in the MongoDB configuration file, we need to restart the MongoDB service with the following command for the changes to take effect:<\/p>\n<pre>sudo systemctl restart mongod<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step-4-Creating-Administrative-MongoDB-User\"><\/span>Step 4: Creating Administrative MongoDB User<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Since we configured the MongoDB server and enabled the authentication option, we now need to create an administrative MongoDB user account which will be used to manage the MongoDB instance.<\/p>\n<p>To access the mongo shell, type:<\/p>\n<pre>mongo<\/pre>\n<p>Next, we will use the following command to connect to the admin database:<\/p>\n<pre>use admin<\/pre>\n<p>Output:<\/p>\n<pre>switched to db admin<\/pre>\n<p>We will perform the following command to create a new administrative user called mongo_admin with the userAdminAnyDatabase role:<\/p>\n<pre>db.createUser(\n{\nuser: \"mongo_admin\", \npwd: \"<span style=\"color: #ff0000;\">Strong_Pas$w0rd<\/span>\", \nroles: [ { role: \"userAdminAnyDatabase\", db: \"admin\" } ]\n}\n)<\/pre>\n<p>And we will get this as output:<\/p>\n<pre>Successfully added user: {\n\"user\" : \"mongo_admin\",\n\"roles\" : [\n{\n\"role\" : \"userAdminAnyDatabase\",\n\"db\" : \"admin\"\n}\n]\n}<\/pre>\n<p>Don&#8217;t forget to replace <span style=\"color: #ff0000;\">&#8216;Strong_Pas$w0rd&#8217; <\/span>with an actual strong password. We can now exit the mongo shell:<\/p>\n<pre>quit()<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step-5-Verifying-the-Administrative-Users-Access\"><\/span>Step 5: Verifying the Administrative User&#8217;s Access<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To confirm the changes, we will access the mongo shell using the mongo_admin user we created:<\/p>\n<pre>mongo -u mongo_admin -p --authenticationDatabase admin\n\nuse admin\n\nshow users<\/pre>\n<p>And if you followed all of the steps so far, you should have the following output:<\/p>\n<p>Output:<\/p>\n<pre>&gt; use admin\nswitched to db admin\n&gt; show users\n{\n\"_id\" : \"admin.mongo_admin\",\n\"user\" : \"mongo_admin\",\n\"db\" : \"admin\",\n\"roles\" : [\n{\n\"role\" : \"userAdminAnyDatabase\",\n\"db\" : \"admin\"\n}\n],\n\"mechanisms\" : [\n\"SCRAM-SHA-1\",\n\"SCRAM-SHA-256\"\n]\n}<\/pre>\n<p>You can also try to list the users when you access the mongo shell (without arguments) and use the same commands as we used before.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step-6-Allow-Remote-MongoDB-Access-in-the-Firewall\"><\/span>Step 6: Allow Remote MongoDB Access in the Firewall<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In this step, we will provide remote access to our MongoDB by allowing it in our firewall. If you do not use any firewall on your server, you can skip this step. The default port of MongoDB is 27017, so in our examples, we&#8217;ll show you how to allow this port through your firewall.<\/p>\n<p>If you are using the UFW (Uncomplicated Firewall) then you can use the following tips on how to allow MongoDB to be remotely accessible.<\/p>\n<p>To allow access to MongoDB on its default port (27017) from everywhere, you can use the following command:<\/p>\n<pre>sudo ufw allow 27017<\/pre>\n<p>To allow access to MongoDB on its default port 27017 from a specific IP address only, you can use the command:<\/p>\n<pre>sudo ufw allow from <span style=\"color: #ff0000;\">allowed_IP_address<\/span>\/32 to any port 27017<\/pre>\n<p>You will need to change <span style=\"color: #ff0000;\">allowed_IP_address<\/span> with the actual IP address that you want to use.<\/p>\n<p>You can confirm the change to the firewall settings with:<\/p>\n<pre>sudo ufw status<\/pre>\n<p>Output:<\/p>\n<pre>Status: active\n\nTo                         Action      From\n--                         ------      ----\n27017                      ALLOW       Anywhere\nOpenSSH                    ALLOW       Anywhere\n27017 (v6)                 ALLOW       Anywhere (v6)\nOpenSSH (v6)               ALLOW       Anywhere (v6)\n<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step-7-Connect-to-MongoDB\"><\/span>Step 7: Connect to MongoDB<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now that we installed and configured MongoDB, we need to mention a few different ways on how to connect to it. We need to make sure that our MongoDB configuration works before we attempt to access the Mongo shell.<\/p>\n<p><strong>Local MongoDB Instance on Default Port<\/strong><\/p>\n<p>The most basic connection to the mongo shell is just running the mongo command without any arguments:<\/p>\n<pre>mongo<\/pre>\n<p><strong>Local MongoDB Instance on a Non-default Port<\/strong><\/p>\n<p>If we want to connect to the Mongo shell on a specific port then we can use:<\/p>\n<pre>mongo --port <span style=\"color: #ff0000;\">port_number<\/span><\/pre>\n<p>Just replace the\u00a0<span style=\"color: #ff0000;\">port_number<\/span> with your actual port number.<\/p>\n<p><strong>MongoDB Instance on a Remote Host<\/strong><\/p>\n<p>If we need to connect to a remote host machine with the MongoDB instance, we can use the following ways:<\/p>\n<p>We can specify a connection string.<\/p>\n<pre>mongo mongodb:\/\/<span style=\"color: #ff0000;\">your_domain_name.com<\/span>:port_number<\/pre>\n<p>We can use the command-line option &#8211;host &lt;host&gt;:&lt;port&gt;<\/p>\n<pre>mongo --host <span style=\"color: #ff0000;\">your_domain_name.com<\/span>:port_number<\/pre>\n<p>or we can use the &#8211;host &lt;host&gt; and &#8211;port &lt;port&gt;<\/p>\n<pre>mongo --host <span style=\"color: #ff0000;\">your_domain_name.com<\/span> --port port_number<\/pre>\n<p><strong>MongoDB Instance with Authentication<\/strong><\/p>\n<p>We will use these examples to show you how to connect to a MongoDB instance that requires authentication.<\/p>\n<p>We can define the username, authentication database and the port number in our connection string. Also, we can define the password (which is optional) in our connection string. If the password is not defined in our connection string then the shell will prompt for the password.<\/p>\n<pre>mongo --host mongodb:\/\/user@<span style=\"color: #ff0000;\">your_domain_name.com<\/span>:port_number\/?authSource=admin<\/pre>\n<p>We can use the &#8211;username &lt;user&gt;, &#8211;password, and &#8211;authenticationDatabase &lt;db&gt; command-line options.<\/p>\n<pre>mongo --username user --password --authenticationDatabase admin --host <span style=\"color: #ff0000;\">your_domain_name.com<\/span> --port port_number<\/pre>\n<p><strong>Connect to a MongoDB Replica Set<\/strong><\/p>\n<p>We can specify the replica set name and members in the connection string.<\/p>\n<pre>mongo mongodb:\/\/<span style=\"color: #ff0000;\">your_domain_name.com<\/span>.local:port_number,mongodb1.<span style=\"color: #ff0000;\">your_domain_name.com<\/span>.local:port_number,mongodb2.<span style=\"color: #ff0000;\">your_domain_name.com<\/span>.local:port_number\/?replicaSet=replA<\/pre>\n<p>If you are using the DNS Seedlist Connection Format, you can specify the connection string:<\/p>\n<pre>mongo \"mongodb+srv:\/\/server.<span style=\"color: #ff0000;\">your_domain_name.com<\/span>\/\"<\/pre>\n<p>We can specify the replica set name and members from the &#8211;host &lt;replica set name&gt;\/&lt;host1&gt;:&lt;port1&gt;,&lt;host2&gt;:&lt;port2&gt;,&#8230; In this example to connect to a replica set named replA:<\/p>\n<pre>mongo --host replA\/<span style=\"color: #ff0000;\">your_domain_name.com<\/span>.local:port_number,mongodb1.<span style=\"color: #ff0000;\">your_domain_name.com<\/span>.local:port_number,mongodb2.<span style=\"color: #ff0000;\">your_domain_name.com<\/span>.local:port_number<\/pre>\n<p><strong>TLS\/SSL Connection<\/strong><\/p>\n<p>We can specify the ssl=true option in the connection string.<\/p>\n<pre>mongo mongodb:\/\/your_domain_name.com.local:port_number,mongodb1.your_domain_name.com.local:port_number,mongodb2.your_domain_name.com.local:port_number\/?replicaSet=replA&amp;ssl=true<\/pre>\n<p>or we can specify &#8211;ssl in the command line and use the previous example on how to connect to the replica set named replA:<\/p>\n<pre>mongo --ssl --host replA\/your_domain_name.com.local:port_number,mongodb1.your_domain_name.com.local:port_number,mongodb2.your_domain_name.com.local:port_number<\/pre>\n<p>If you want to use the above commands, don&#8217;t forget to replace the values like <span style=\"color: #ff0000;\">your_domain_name.com<\/span>, host_name, user, and replA in the commands with the actual values.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step-8-Uninstall-MongoDB\"><\/span>Step 8: Uninstall MongoDB<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If for any reason you do not like MongoDB and you need to remove it from your system, you can follow these commands:<\/p>\n<pre>sudo service mongod stop\nsudo apt purge mongodb-org*\nsudo rm -r \/var\/log\/mongodb\nsudo rm -r \/var\/lib\/mongodb<\/pre>\n<p>In this article, we showed you how to install MongoDB, customize the firewall, create an admin user, enable remote access, connect to MongoDB and how to uninstall and remove MongoDB. Now you can use this knowledge and can start with building your projects in this wonderful application.<\/p>\n<hr \/>\n<p><img decoding=\"async\" class=\"alignleft size-full wp-image-31786\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/08\/managed-database-setup-support-mongodb-configuration-for-ubuntu18.04-server.jpg\" alt=\"\" width=\"150\" height=\"150\" \/>Of course, if you are one of our <a href=\"https:\/\/www.rosehosting.com\/ubuntu-hosting.html\" target=\"_blank\" rel=\"noopener noreferrer\">Ubuntu Hosting<\/a> customers, or if you have one of our\u00a0<a href=\"https:\/\/www.rosehosting.com\/mongodb-hosting.html\" target=\"_blank\" rel=\"noopener noreferrer\">Managed MongoDB Hosting<\/a>\u00a0plans, you don&#8217;t have to install MongoDB on your Ubuntu 18.04 VPS \u2013 simply ask our admins, sit back, and relax. Our admins will install MongoDB on Ubuntu 18.04 for you immediately.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>PS<\/strong><\/span>. If you liked this post about <strong>how to install MongoDB on an Ubuntu 18.04 VPS<\/strong>, please share it with your friends on the social networks using the buttons below, or simply leave a comment in the comments section. Thanks.<\/p>\n<p>New version available here: <a href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-20-04-and-centos-8\/\">How to Install MongoDB on Ubuntu 20.04 and CentOS 8<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will show you how to install MongoDB, manage its services, and allow remote connections on an\u00a0Ubuntu &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Install MongoDB on Ubuntu 18.04\" class=\"read-more button\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#more-29960\" aria-label=\"Read more about How to Install MongoDB on Ubuntu 18.04\">Read More<\/a><\/p>\n","protected":false},"author":4,"featured_media":31784,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1702,1698],"tags":[],"class_list":["post-29960","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-databases","category-ubuntu","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.5 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Install MongoDB on Ubuntu 18.04 | RoseHosting<\/title>\n<meta name=\"description\" content=\"How to Install MongoDB on Ubuntu 18.04 | RoseHosting\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Install MongoDB on Ubuntu 18.04\" \/>\n<meta property=\"og:description\" content=\"How to Install MongoDB on Ubuntu 18.04 | RoseHosting\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/\" \/>\n<meta property=\"og:site_name\" content=\"RoseHosting\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/RoseHosting\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/rosehosting.helpdesk\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-22T15:44:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-03T08:33:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/08\/how-to-install-mongodb-on-ubuntu18.04.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"742\" \/>\n\t<meta property=\"og:image:height\" content=\"372\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jeff Wilson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rosehosting\" \/>\n<meta name=\"twitter:site\" content=\"@rosehosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeff Wilson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/\"},\"author\":{\"name\":\"Jeff Wilson\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/person\\\/7ce77a842fa6a9a7f8efa186f2353713\"},\"headline\":\"How to Install MongoDB on Ubuntu 18.04\",\"datePublished\":\"2019-08-22T15:44:27+00:00\",\"dateModified\":\"2022-06-03T08:33:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/\"},\"wordCount\":1425,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/how-to-install-mongodb-on-ubuntu18.04.jpg\",\"articleSection\":[\"Databases\",\"Ubuntu\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/\",\"name\":\"How to Install MongoDB on Ubuntu 18.04 | RoseHosting\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/how-to-install-mongodb-on-ubuntu18.04.jpg\",\"datePublished\":\"2019-08-22T15:44:27+00:00\",\"dateModified\":\"2022-06-03T08:33:33+00:00\",\"description\":\"How to Install MongoDB on Ubuntu 18.04 | RoseHosting\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/how-to-install-mongodb-on-ubuntu18.04.jpg\",\"contentUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/how-to-install-mongodb-on-ubuntu18.04.jpg\",\"width\":742,\"height\":372},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-install-mongodb-on-ubuntu-18-04\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Install MongoDB on Ubuntu 18.04\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\",\"name\":\"RoseHosting.com\",\"description\":\"Premium Linux Tutorials Since 2001\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\",\"name\":\"RoseHosting\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/android-chrome-192x192-1.png\",\"contentUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/android-chrome-192x192-1.png\",\"width\":192,\"height\":192,\"caption\":\"RoseHosting\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/RoseHosting\",\"https:\\\/\\\/x.com\\\/rosehosting\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/rosehosting\\\/\"],\"description\":\"RoseHosting is a leading Linux hosting provider, serving thousands of clients world-wide since 2001.\",\"email\":\"info@rosehosting.com\",\"telephone\":\"(314) 275-0414\",\"legalName\":\"Rose Web Services LLC\",\"foundingDate\":\"2001-04-02\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"11\",\"maxValue\":\"50\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/person\\\/7ce77a842fa6a9a7f8efa186f2353713\",\"name\":\"Jeff Wilson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"caption\":\"Jeff Wilson\"},\"description\":\"An experienced Linux veteran with many years of experience. Helping other Linux admins with frequent Linux and business-related blog posts on the RoseHosting blog. Techie by choice. Loving nature and travel. Happily married and father of two lovely children.\",\"sameAs\":[\"https:\\\/\\\/www.rosehosting.com\",\"https:\\\/\\\/www.facebook.com\\\/rosehosting.helpdesk\"],\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/author\\\/jwilson\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Install MongoDB on Ubuntu 18.04 | RoseHosting","description":"How to Install MongoDB on Ubuntu 18.04 | RoseHosting","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/","og_locale":"en_US","og_type":"article","og_title":"How to Install MongoDB on Ubuntu 18.04","og_description":"How to Install MongoDB on Ubuntu 18.04 | RoseHosting","og_url":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/","og_site_name":"RoseHosting","article_publisher":"https:\/\/www.facebook.com\/RoseHosting","article_author":"https:\/\/www.facebook.com\/rosehosting.helpdesk","article_published_time":"2019-08-22T15:44:27+00:00","article_modified_time":"2022-06-03T08:33:33+00:00","og_image":[{"width":742,"height":372,"url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/08\/how-to-install-mongodb-on-ubuntu18.04.jpg","type":"image\/jpeg"}],"author":"Jeff Wilson","twitter_card":"summary_large_image","twitter_creator":"@rosehosting","twitter_site":"@rosehosting","twitter_misc":{"Written by":"Jeff Wilson","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#article","isPartOf":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/"},"author":{"name":"Jeff Wilson","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/person\/7ce77a842fa6a9a7f8efa186f2353713"},"headline":"How to Install MongoDB on Ubuntu 18.04","datePublished":"2019-08-22T15:44:27+00:00","dateModified":"2022-06-03T08:33:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/"},"wordCount":1425,"commentCount":0,"publisher":{"@id":"https:\/\/www.rosehosting.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#primaryimage"},"thumbnailUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/08\/how-to-install-mongodb-on-ubuntu18.04.jpg","articleSection":["Databases","Ubuntu"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/","url":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/","name":"How to Install MongoDB on Ubuntu 18.04 | RoseHosting","isPartOf":{"@id":"https:\/\/www.rosehosting.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#primaryimage"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#primaryimage"},"thumbnailUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/08\/how-to-install-mongodb-on-ubuntu18.04.jpg","datePublished":"2019-08-22T15:44:27+00:00","dateModified":"2022-06-03T08:33:33+00:00","description":"How to Install MongoDB on Ubuntu 18.04 | RoseHosting","breadcrumb":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#primaryimage","url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/08\/how-to-install-mongodb-on-ubuntu18.04.jpg","contentUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/08\/how-to-install-mongodb-on-ubuntu18.04.jpg","width":742,"height":372},{"@type":"BreadcrumbList","@id":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-ubuntu-18-04\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.rosehosting.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Install MongoDB on Ubuntu 18.04"}]},{"@type":"WebSite","@id":"https:\/\/www.rosehosting.com\/blog\/#website","url":"https:\/\/www.rosehosting.com\/blog\/","name":"RoseHosting.com","description":"Premium Linux Tutorials Since 2001","publisher":{"@id":"https:\/\/www.rosehosting.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.rosehosting.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.rosehosting.com\/blog\/#organization","name":"RoseHosting","url":"https:\/\/www.rosehosting.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/03\/android-chrome-192x192-1.png","contentUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/03\/android-chrome-192x192-1.png","width":192,"height":192,"caption":"RoseHosting"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/RoseHosting","https:\/\/x.com\/rosehosting","https:\/\/www.linkedin.com\/in\/rosehosting\/"],"description":"RoseHosting is a leading Linux hosting provider, serving thousands of clients world-wide since 2001.","email":"info@rosehosting.com","telephone":"(314) 275-0414","legalName":"Rose Web Services LLC","foundingDate":"2001-04-02","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"11","maxValue":"50"}},{"@type":"Person","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/person\/7ce77a842fa6a9a7f8efa186f2353713","name":"Jeff Wilson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","caption":"Jeff Wilson"},"description":"An experienced Linux veteran with many years of experience. Helping other Linux admins with frequent Linux and business-related blog posts on the RoseHosting blog. Techie by choice. Loving nature and travel. Happily married and father of two lovely children.","sameAs":["https:\/\/www.rosehosting.com","https:\/\/www.facebook.com\/rosehosting.helpdesk"],"url":"https:\/\/www.rosehosting.com\/blog\/author\/jwilson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/29960","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/comments?post=29960"}],"version-history":[{"count":1,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/29960\/revisions"}],"predecessor-version":[{"id":36466,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/29960\/revisions\/36466"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/media\/31784"}],"wp:attachment":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/media?parent=29960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/categories?post=29960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/tags?post=29960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}