{"id":8101,"date":"2021-03-09T20:32:57","date_gmt":"2021-03-09T17:32:57","guid":{"rendered":"https:\/\/kifarunix.com\/?p=8101"},"modified":"2024-03-19T19:22:09","modified_gmt":"2024-03-19T16:22:09","slug":"install-mongodb-on-ubuntu","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-mongodb-on-ubuntu\/","title":{"rendered":"Install MongoDB on Ubuntu 20.04"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"983\" height=\"345\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/03\/install-mongodb-ubuntu.png\" alt=\"Install MongoDB on Ubuntu 20.04\" class=\"wp-image-8105\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/03\/install-mongodb-ubuntu.png?v=1615306791 983w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/03\/install-mongodb-ubuntu-768x270.png?v=1615306791 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/03\/install-mongodb-ubuntu-150x53.png?v=1615306791 150w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/03\/install-mongodb-ubuntu-300x105.png?v=1615306791 300w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/03\/install-mongodb-ubuntu-696x244.png?v=1615306791 696w\" sizes=\"(max-width: 983px) 100vw, 983px\" \/><\/figure>\n\n\n\n<p>Follow through this tutorial to learn how to install MongoDB on Ubuntu 20.04. According to <a aria-label=\"mongodb.com (opens in a new tab)\" href=\"https:\/\/www.mongodb.com\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">mongodb.com<\/a>, &#8220;<em>MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era.<\/em>..<em>It is a scalable, flexible&nbsp;<a href=\"https:\/\/www.mongodb.com\/nosql-explained\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">NoSQL<\/a>&nbsp;document database platform designed to overcome the relational databases approach and the limitations of other NoSQL solutions.<\/em>&#8220;<\/p>\n\n\n\n<p>Read about <a aria-label=\"top 5 features of MongoDB (opens in a new tab)\" href=\"https:\/\/www.mongodb.com\/what-is-mongodb\/features\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">top 5 features of MongoDB<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing MongoDB on Ubuntu 20.04<\/h2>\n\n\n\n<p>MongoDB is available in both a community and an enterprise version;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>MongoDB Community is the&nbsp;<a aria-label=\" (opens in a new tab)\" href=\"https:\/\/github.com\/mongodb\/mongo\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">source available and free to use<\/a>&nbsp;edition of MongoDB.<\/em><\/li>\n\n\n\n<li><em>MongoDB Enterprise is available as part of the MongoDB Enterprise Advanced subscription and includes comprehensive support for your MongoDB deployment. MongoDB Enterprise also adds enterprise-focused features such as LDAP and Kerberos support, on-disk encryption, and auditing.<\/em><\/li>\n<\/ul>\n\n\n\n<p>In this tutorial, we will learn how to install MongoDB community edition on Ubuntu 20.04.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install MongoDB Community Edition on Ubuntu 20.04<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Install MongoDB APT Repo on Ubuntu 20.04<\/h4>\n\n\n\n<p>To be able to install the latest stable versions of MongoDB on Ubuntu 20.04, you need to install MongoDB APT repository list.<\/p>\n\n\n\n<p>As of this writing, MongoDB 4.4 is the current stable LTS release version. Be sure to replace the version numbers in the commands below accordingly.<\/p>\n\n\n\n<p>Begin by installing the MongoDB APT repo signing key;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install gnupg<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>wget -qO - https:\/\/www.mongodb.org\/static\/pgp\/server-4.4.asc | sudo apt-key add -<\/code><\/pre>\n\n\n\n<p>Next, install MongoDB APT Repo;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>echo \"deb [ arch=amd64,arm64 ] https:\/\/repo.mongodb.org\/apt\/ubuntu focal\/mongodb-org\/4.4 multiverse\" | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-4.4.list<\/code><\/pre>\n\n\n\n<p>Update package cache;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt update<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Install latest version of MongoDB Community Edition on Ubuntu 20.04<\/h4>\n\n\n\n<p>Once the repo list is in place, run the command below to install the latest version of MongoDB on Ubuntu 20.04.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install -y mongodb-org<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Running MongoDB on Ubuntu 20.04<\/h3>\n\n\n\n<p>When installed, MongoDB creates a systemd unit file called, <code><strong>mongod.service<\/strong><\/code>, under <code><strong>\/lib\/systemd\/system\/<\/strong><\/code>.<\/p>\n\n\n\n<p>This service unit file can be used to manage MongoDB.<\/p>\n\n\n\n<p>To start MongoDB service, execute the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl start mongod<\/code><\/pre>\n\n\n\n<p>To check the status;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl status mongod<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\u25cf mongod.service - MongoDB Database Server\n     Loaded: loaded (\/lib\/systemd\/system\/mongod.service; disabled; vendor preset: enabled)\n     Active: active (running) since Tue 2021-03-09 16:56:41 UTC; 2min 8s ago\n       Docs: https:\/\/docs.mongodb.org\/manual\n   Main PID: 6618 (mongod)\n     Memory: 60.4M\n     CGroup: \/system.slice\/mongod.service\n             \u2514\u25006618 \/usr\/bin\/mongod --config \/etc\/mongod.conf\n\nMar 09 16:56:41 ubuntu20 systemd[1]: Started MongoDB Database Server.<\/code><\/pre>\n\n\n\n<p>To enable it to start on boot;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable mongod<\/code><\/pre>\n\n\n\n<p>You can restart or stop is by executing the commands below respectively;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart mongod<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl stop mongod<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Connecting to MongoDB on Ubuntu<\/h3>\n\n\n\n<p>By default, MongoDB listens on TCP port 27017 by default, on a localhost.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install net-tools<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>netstat -altnp | grep :27<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      6618\/mongod<\/code><\/pre>\n\n\n\n<p>In order to connect to it, you need to be logged in to the same host on which MongoDB is running and simply execute the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mongo<\/code><\/pre>\n\n\n\n<p>The command above will launch an interactive MongoDB shell;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MongoDB shell version v4.4.4\nconnecting to: mongodb:\/\/127.0.0.1:27017\/?compressors=disabled&amp;gssapiServiceName=mongodb\nImplicit session: session { \"id\" : UUID(\"9d73e6f2-1a6e-4ea7-8887-a71f81dc1cd9\") }\nMongoDB server version: 4.4.4\nWelcome to the MongoDB shell.\nFor interactive help, type \"help\".\nFor more comprehensive documentation, see\n\thttps:&#47;&#47;docs.mongodb.com\/\nQuestions? Try the MongoDB Developer Community Forums\n\thttps:\/\/community.mongodb.com\n---\n...\n---\n&gt;<\/code><\/pre>\n\n\n\n<p>To obtain help while logged into the MongoDB interactive shell, run the <strong><code>help<\/code><\/strong> command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>help<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&gt; help\n\tdb.help()                    help on db methods\n\tdb.mycoll.help()             help on collection methods\n\tsh.help()                    sharding helpers\n\trs.help()                    replica set helpers\n\thelp admin                   administrative help\n\thelp connect                 connecting to a db help\n\thelp keys                    key shortcuts\n\thelp misc                    misc things to know\n\thelp mr                      mapreduce\n\n\tshow dbs                     show database names\n\tshow collections             show collections in current database\n\tshow users                   show users in current database\n\tshow profile                 show most recent system.profile entries with time &gt;= 1ms\n\tshow logs                    show the accessible logger names\n\tshow log [name]              prints out the last segment of log in memory, 'global' is default\n\tuse &lt;db_name&gt;                set current database\n\tdb.mycoll.find()             list objects in collection mycoll\n\tdb.mycoll.find( { a : 1 } )  list objects in mycoll where a == 1\n\tit                           result of the last line evaluated; use to further iterate\n\tDBQuery.shellBatchSize = x   set default number of items to display on shell\n\texit                         quit the mongo shell\n&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Uninstall MongoDB CE on Ubuntu 20.04<\/h2>\n\n\n\n<p>If for some reasons you want to uninstall MongoDB and remove it completely on Ubuntu 20.04, you would simply have to stop and purge its by running the commands below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl stop mongod<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt remove --purge --auto-remove mongodb-org<\/code><\/pre>\n\n\n\n<p>Remove MongoDB databases;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>rm -rf \/var\/lib\/mongodb<\/code><\/pre>\n\n\n\n<p>Learn how to enable MongoDB authentication by following the link below;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/enable-authentication-on-mongodb\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Enable Authentication on MongoDB<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Reference<\/h4>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/docs.mongodb.com\/manual\/tutorial\/install-mongodb-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Install MongoDB community Edition on Ubuntu<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Further Reading<\/h4>\n\n\n\n<p><a aria-label=\"Getting Started with MongoDB (opens in a new tab)\" href=\"https:\/\/docs.mongodb.com\/manual\/tutorial\/getting-started\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Getting Started with MongoDB<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-libmodsecurity-with-apache-on-ubuntu-20-04\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Install LibModsecurity with Apache on Ubuntu 20.04<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-libmodsecurity-with-apache-on-ubuntu-20-04\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Update\/Change Kibana Visualization Index Pattern<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-libmodsecurity-with-apache-on-ubuntu-20-04\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Request control during screen share in Teams on Linux<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-libmodsecurity-with-apache-on-ubuntu-20-04\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Install Arkime (Moloch) Full Packet Capture tool on Ubuntu<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Follow through this tutorial to learn how to install MongoDB on Ubuntu 20.04. According to mongodb.com, &#8220;MongoDB is a general purpose, document-based, distributed database built<\/p>\n","protected":false},"author":3,"featured_media":8105,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[299,121],"tags":[3209,3206,3210,3211,961,3208,3207],"class_list":["post-8101","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database","category-howtos","tag-install-mongodb-linux","tag-install-mongodb-on-ubuntu","tag-mongo","tag-mongod","tag-mongodb","tag-mongodb-install-ubuntu-20-04","tag-ubuntu-20-04-mongodb-install","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8101"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=8101"}],"version-history":[{"count":6,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8101\/revisions"}],"predecessor-version":[{"id":21917,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8101\/revisions\/21917"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/8105"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=8101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=8101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=8101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}