{"id":10706,"date":"2019-03-08T12:54:58","date_gmt":"2019-03-08T12:54:58","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=10706"},"modified":"2019-03-09T21:28:47","modified_gmt":"2019-03-09T21:28:47","slug":"install-mongodb-community-edition-4-0-on-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/08\/install-mongodb-community-edition-4-0-on-linux\/","title":{"rendered":"Install MongoDB Community Edition 4.0 on Linux"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/udemy-images.udemy.com\/course\/750x422\/1906852_93c6.jpg\" alt=\"Image result for mongodb images\" \/><\/p>\n<p><strong>MongoDB<\/strong>\u00a0is an open source no-schema and high-performance document-oriented NoSQL database (NoSQL means it doesn\u2019t provide any tables, rows, etc.) system much like\u00a0<a href=\"https:\/\/www.tecmint.com\/install-apache-couchdb-in-rhel-centos-debian-and-ubuntu\/\">Apache CouchDB<\/a>. It stores data in JSON-like documents with dynamic schema\u2019s for better performance.<\/p>\n<h4>MongoDB Packages<\/h4>\n<p>Following are the supported MongoDB packages, comes with own repository and contains:<\/p>\n<ol>\n<li><code>mongodb-org<\/code>\u00a0\u2013 A metapackage that will install following 4 component packages automatically.<\/li>\n<li><code>mongodb-org-server<\/code>\u00a0\u2013 Contains the mongod daemon and releated configuration and init scripts.<\/li>\n<li><code>mongodb-org-mongos<\/code>\u00a0\u2013 Contains the mongos daemon.<\/li>\n<li><code>mongodb-org-shell<\/code>\u00a0\u2013 Contains the mongo shell.<\/li>\n<li><code>mongodb-org-tools<\/code>\u00a0\u2013 Contains the MongoDB tools: mongo, mongodump, mongorestore, mongoexport, mongoimport, mongostat, mongotop, bsondump, mongofiles, mongooplog and mongoperf.<\/li>\n<\/ol>\n<p>In this article, we will walk you through the process of installing\u00a0<strong>MongoDB 4.0 Community Edition<\/strong>\u00a0on\u00a0<strong>RHEL<\/strong>,\u00a0<strong>CentOS<\/strong>,\u00a0<strong>Fedora<\/strong>,\u00a0<strong>Ubuntu<\/strong>\u00a0and\u00a0<strong>Debian<\/strong>\u00a0servers with the help of official MongoDB repository using\u00a0<strong>.rpm<\/strong>\u00a0and\u00a0<strong>.deb<\/strong>packages on 64-bit systems only.<\/p>\n<h3>Step 1: Adding MongoDB Repository<\/h3>\n<p>First, we need to add\u00a0<strong>MongoDB Official Repository<\/strong>\u00a0to install\u00a0<strong>MongoDB Community Edition<\/strong>\u00a0on\u00a0<strong>64-bit<\/strong>\u00a0platforms.<\/p>\n<h4>On Red Hat, CentOS and Fedora<\/h4>\n<p>Create a file\u00a0<code>\/etc\/yum.repos.d\/mongodb-org-4.0.repo<\/code>\u00a0to install MongoDB directly, using\u00a0<a href=\"https:\/\/www.tecmint.com\/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement\/\" target=\"_blank\" rel=\"noopener\">yum command<\/a>.<\/p>\n<pre># vi \/etc\/yum.repos.d\/mongodb-org-4.0.repo\r\n<\/pre>\n<p>Now add the following repository file.<\/p>\n<pre>[mongodb-org-4.0]\r\nname=MongoDB Repository\r\nbaseurl=https:\/\/repo.mongodb.org\/yum\/redhat\/$releasever\/mongodb-org\/4.0\/x86_64\/\r\ngpgcheck=1\r\nenabled=1\r\ngpgkey=https:\/\/www.mongodb.org\/static\/pgp\/server-4.0.asc\r\n<\/pre>\n<h4>On Ubuntu Systems<\/h4>\n<p>MongoDB repository only provides packages for\u00a0<strong>18.04 LTS (bionic)<\/strong>,\u00a0<strong>16.04 LTS (xenial)<\/strong>\u00a0and\u00a0<strong>14.04 LTS (Trusty Tahr)<\/strong>\u00a0long-term supported 64bit Ubuntu releases.<\/p>\n<p>To install\u00a0<strong>MongoDB Community Edition<\/strong>\u00a0on Ubuntu, you need to first import the public key used by the package management system.<\/p>\n<pre>$ sudo apt-key adv --keyserver hkp:\/\/keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4\r\n<\/pre>\n<p>Next, create a MongoDB repository file and update the repository as shown.<\/p>\n<h5>On Ubuntu 18.04<\/h5>\n<pre>$ echo \"deb [ arch=amd64 ] https:\/\/repo.mongodb.org\/apt\/ubuntu bionic\/mongodb-org\/4.0 multiverse\" | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-4.0.list\r\n$ sudo apt-get update\r\n<\/pre>\n<h5>On Ubuntu 16.04<\/h5>\n<pre>$ echo \"deb [ arch=amd64,arm64 ] https:\/\/repo.mongodb.org\/apt\/ubuntu xenial\/mongodb-org\/4.0 multiverse\" | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-4.0.list\r\n$ sudo apt-get update\r\n<\/pre>\n<h5>On Ubuntu 14.04<\/h5>\n<pre>$ echo \"deb [ arch=amd64 ] https:\/\/repo.mongodb.org\/apt\/ubuntu trusty\/mongodb-org\/4.0 multiverse\" | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-4.0.list\r\n$ sudo apt-get update\r\n<\/pre>\n<h4>On Debian Systems<\/h4>\n<p>MongoDB repository only provides packages for 64-bit\u00a0<strong>Debian 9 Stretch<\/strong>\u00a0and\u00a0<strong>Debian 8 Jessie<\/strong>, to install MongoDB on Debian, you need to run the following series of commands:<\/p>\n<h5>On Debian 9<\/h5>\n<pre>$ sudo apt-key adv --keyserver hkp:\/\/keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4\r\n$ echo \"deb http:\/\/repo.mongodb.org\/apt\/debian stretch\/mongodb-org\/4.0 main\" | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-4.0.list\r\n$ sudo apt-get update\r\n<\/pre>\n<h5>On Debian 8<\/h5>\n<pre>$ sudo apt-key adv --keyserver hkp:\/\/keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4\r\n$ echo \"deb http:\/\/repo.mongodb.org\/apt\/debian jessie\/mongodb-org\/4.0 main\" | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-4.0.list\r\n$ sudo apt-get update\r\n<\/pre>\n<h3>Step 2: Installing MongoDB Community Edition Packages<\/h3>\n<p>Once the repo installed, run the following command to install\u00a0<strong>MongoDB 4.0<\/strong>.<\/p>\n<pre># yum install -y mongodb-org               [On <strong>RPM<\/strong> based Systems]\r\n$ sudo apt-get install -y mongodb-org      [On <strong>DEB<\/strong> based Systems]\r\n<\/pre>\n<p>To install a particular MongoDB release version, include each component package individually and add the version number to the package name, as shown in the following example:<\/p>\n<pre>-------------- On <strong>RPM<\/strong> based Systems --------------\r\n# yum install -y mongodb-org-4.0.6 mongodb-org-server-4.0.6 mongodb-org-shell-4.0.6 mongodb-org-mongos-4.0.6 mongodb-org-tools-4.0.6\r\n\r\n-------------- On <strong>DEB<\/strong> based Systems --------------\r\n$ sudo apt-get install -y mongodb-org=4.0.6 mongodb-org-server=4.0.6 mongodb-org-shell=4.0.6 mongodb-org-mongos=4.0.6 mongodb-org-tools=4.0.6\r\n<\/pre>\n<h3>Step 3: Configure MongoDB Community Edition<\/h3>\n<p>Open file\u00a0<code>\/etc\/mongod.conf<\/code>\u00a0and verify below basic settings. If commented any settings, please un-comment it.<\/p>\n<pre># vi \/etc\/mongod.conf<\/pre>\n<pre>path: \/var\/log\/mongodb\/mongod.log\r\nport=27017\r\ndbpath=\/var\/lib\/mongo\r\n<\/pre>\n<p><strong>Note<\/strong>: This step is only applicable for\u00a0<strong>Red Hat<\/strong>\u00a0based distributions,\u00a0<strong>Debian<\/strong>\u00a0and\u00a0<strong>Ubuntu<\/strong>\u00a0users can ignore it.<\/p>\n<p>Now open port\u00a0<code>27017<\/code>\u00a0on the firewall.<\/p>\n<pre>-------------- On <strong>FirewallD<\/strong> based Systems --------------\r\n# firewall-cmd --zone=public --add-port=27017\/tcp --permanent\r\n# firewall-cmd --reload\r\n\r\n-------------- On <strong>IPtables<\/strong> based Systems --------------\r\n# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT\r\n<\/pre>\n<h3>Step 4: Run MongoDB Community Edition<\/h3>\n<p>Now it\u2019s time to start the\u00a0<code>mongod<\/code>\u00a0process by issuing the following command:<\/p>\n<pre># service mongod start\r\nOR               \r\n$ sudo service mongod start\r\n<\/pre>\n<p>You can make sure that the\u00a0<code>mongod<\/code>\u00a0process has been started successfully by verifying the contents of\u00a0<code>\/var\/log\/mongodb\/mongod.log<\/code>\u00a0log file for a line reading.<\/p>\n<pre>2019-03-05T01:33:47.121-0500 I NETWORK  [initandlisten] waiting for connections on port 27017\r\n<\/pre>\n<p>Also you can start, stop or restart\u00a0<code>mongod<\/code>\u00a0process by issuing the following commands:<\/p>\n<pre># service mongod start\r\n# service mongod stop\r\n# service mongod restart\r\n<\/pre>\n<p>Now enable\u00a0<code>mongod<\/code>\u00a0process at system boot.<\/p>\n<pre># systemctl enable mongod.service     [On <strong>SystemD<\/strong> based Systems]\r\n# chkconfig mongod on                 [On <strong>SysVinit<\/strong> based Systems]\r\n<\/pre>\n<h3>Step 5: Begin using MongoDB<\/h3>\n<p>Connect to your\u00a0<strong>MongoDB<\/strong>\u00a0shell by using following command.<\/p>\n<pre># mongo<\/pre>\n<h4>Command Ouput :<\/h4>\n<pre>MongoDB shell version v4.0.6\r\nconnecting to: mongodb:\/\/127.0.0.1:27017\/?gssapiServiceName=mongodb\r\nImplicit session: session { \"id\" : UUID(\"70ffe350-a41f-42b9-871a-17ccde28ba24\") }\r\nMongoDB server version: 4.0.6\r\nWelcome to the MongoDB shell.\r\n<\/pre>\n<p>This command will connect to your\u00a0<strong>MongoDB<\/strong>\u00a0database. Run the following basic commands.<\/p>\n<pre>&gt; show dbs\r\n&gt; show collections\r\n&gt; show users\r\n&gt; use &lt;db name&gt;\r\n&gt; exit\r\n<\/pre>\n<h3>Step 6: Uninstall MongoDB Community Edition<\/h3>\n<p>To completely uninstall MongoDB, you must delete the MongoDB applications, configuration files and directories contains any data and logs.<\/p>\n<p>The following instructions will walk through you the process of removing MongoDB from your system.<\/p>\n<h4>On RHEL, CentOS and Fedora<\/h4>\n<pre># service mongod stop\r\n# yum erase $(rpm -qa | grep mongodb-org)\r\n# rm -r \/var\/log\/mongodb\r\n# rm -r \/var\/lib\/mongo\r\n<\/pre>\n<h4>On Debian and Ubuntu<\/h4>\n<pre>$ sudo service mongod stop\r\n$ sudo apt-get purge mongodb-org*\r\n$ sudo rm -r \/var\/log\/mongodb\r\n$ sudo rm -r \/var\/lib\/mongodb\r\n<\/pre>\n<p>For more information visit official page at\u00a0<a href=\"http:\/\/docs.mongodb.org\/manual\/contents\/\">http:\/\/docs.mongodb.org\/manual\/contents\/<\/a>.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/install-mongodb-on-rhel-centos-fedora-ubuntu-debian\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MongoDB\u00a0is an open source no-schema and high-performance document-oriented NoSQL database (NoSQL means it doesn\u2019t provide any tables, rows, etc.) system much like\u00a0Apache CouchDB. It stores data in JSON-like documents with dynamic schema\u2019s for better performance. MongoDB Packages Following are the supported MongoDB packages, comes with own repository and contains: mongodb-org\u00a0\u2013 A metapackage that will install &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/08\/install-mongodb-community-edition-4-0-on-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Install MongoDB Community Edition 4.0 on Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-10706","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/10706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=10706"}],"version-history":[{"count":2,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/10706\/revisions"}],"predecessor-version":[{"id":11088,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/10706\/revisions\/11088"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=10706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=10706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=10706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}