{"id":22224,"date":"2024-04-21T09:41:36","date_gmt":"2024-04-21T06:41:36","guid":{"rendered":"https:\/\/kifarunix.com\/?p=22224"},"modified":"2024-06-10T18:27:44","modified_gmt":"2024-06-10T15:27:44","slug":"easily-install-mongodb-on-ubuntu-24-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/easily-install-mongodb-on-ubuntu-24-04\/","title":{"rendered":"Easily Install MongoDB on Ubuntu 24.04"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1042\" height=\"584\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2024\/04\/install-mongodb-linux.png?v=1713681503\" alt=\"\" class=\"wp-image-22228\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2024\/04\/install-mongodb-linux.png?v=1713681503 1042w, https:\/\/kifarunix.com\/wp-content\/uploads\/2024\/04\/install-mongodb-linux-768x430.png?v=1713681503 768w\" sizes=\"(max-width: 1042px) 100vw, 1042px\" \/><\/figure>\n\n\n\n<p>In this tutorial to learn how to easily install MongoDB on Ubuntu 24.04. According to <a href=\"https:\/\/www.mongodb.com\/company\/what-is-mongodb\" target=\"_blank\" rel=\"noreferrer noopener\">MongoDB page<\/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;NoSQL&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<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#installing-mongo-db-on-ubuntu-24-04\">Installing MongoDB on Ubuntu 24.04<\/a><ul><li><a href=\"#features-of-mongo-db\">Features of MongoDB<\/a><\/li><li><a href=\"#install-mongo-db-community-edition-on-ubuntu-24-04\">Install MongoDB Community Edition on Ubuntu 24.04<\/a><ul><li><a href=\"#install-mongo-db-apt-repo-on-ubuntu-24-04\">Install MongoDB APT Repo on Ubuntu 24.04<\/a><\/li><li><a href=\"#install-mongo-db-community-edition-on-ubuntu\">Install MongoDB Community Edition on Ubuntu<\/a><\/li><\/ul><\/li><li><a href=\"#running-mongo-db-on-ubuntu-24-04\">Running MongoDB on Ubuntu 24.04<\/a><\/li><li><a href=\"#connecting-to-mongo-db-on-ubuntu\">Connecting to MongoDB on Ubuntu<\/a><\/li><\/ul><\/li><li><a href=\"#uninstall-mongo-db-ce-on-ubuntu-24-04\">Uninstall MongoDB CE on Ubuntu 24.04<\/a><ul><li><a href=\"#reference\">Reference<\/a><\/li><li><a href=\"#further-reading\">Further Reading<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"installing-mongo-db-on-ubuntu-24-04\">Installing MongoDB on Ubuntu 24.04<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"features-of-mongo-db\">Features of MongoDB<\/h3>\n\n\n\n<p>Read about the top features of MongoDB by following the link below.<\/p>\n\n\n\n<p><a aria-label=\"top 5 features of MongoDB (opens in a new tab)\" class=\"rank-math-link\" href=\"https:\/\/www.mongodb.com\/what-is-mongodb\/features\" target=\"_blank\" rel=\"noreferrer noopener\">Top 5 features of MongoDB<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-mongo-db-community-edition-on-ubuntu-24-04\">Install MongoDB Community Edition on Ubuntu 24.04<\/h3>\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. It 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 24.04.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-mongo-db-apt-repo-on-ubuntu-24-04\">Install MongoDB APT Repo on Ubuntu 24.04<\/h4>\n\n\n\n<p>To be able to install the latest stable versions of MongoDB on Ubuntu 24.04, you need to install MongoDB APT repository list.<\/p>\n\n\n\n<p>According to MongoDB <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/release-notes\/\" target=\"_blank\" rel=\"noreferrer noopener\">release notes<\/a> page, MongoDB 7.0 is the current stable LTS release version, as of this writing.<\/p>\n\n\n\n<p>Install the MongoDB APT repo signing key;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install gnupg<\/pre>\n\n\n\n<p>Replace value of the VER variable below with the correct MongoDB release version number.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>VER=7.0<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">wget -qO - https:\/\/www.mongodb.org\/static\/pgp\/server-${VER}.asc | sudo gpg --dearmor -o \/etc\/apt\/trusted.gpg.d\/mongo.gpg<\/pre>\n\n\n\n<p>Next, install MongoDB APT Repository.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"has-small-font-size\">Note that, as of this writing, there are no offical MongoDB repos released for Ubuntu 24.04 Noble Numbat. As such, we will use Ubuntu 22.04 repositories.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-small-font-size\">echo \"deb [arch=amd64,arm64] https:\/\/repo.mongodb.org\/apt\/ubuntu jammy\/mongodb-org\/${VER} multiverse\" | sudo tee \/etc\/apt\/sources.list.d\/mongodb.list<\/pre>\n\n\n\n<p class=\"has-small-font-size\">In the future when you are installing MongoDB, repos might have been released, and instead of the command above, use the command below to install the repository.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-small-font-size\">echo \"deb [arch=amd64,arm64] https:\/\/repo.mongodb.org\/apt\/ubuntu ${lsb_release -sc}\/mongodb-org\/${VER} multiverse\" | sudo tee \/etc\/apt\/sources.list.d\/mongodb.list<\/pre>\n<\/blockquote>\n\n\n\n<p>Update package cache;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt update<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-mongo-db-community-edition-on-ubuntu\">Install MongoDB Community Edition on Ubuntu<\/h4>\n\n\n\n<p>You can now install the latest version of MongoDB.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install -y mongodb-org<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"running-mongo-db-on-ubuntu-24-04\">Running MongoDB on Ubuntu 24.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>. 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\">sudo systemctl start mongod<\/pre>\n\n\n\n<p>To check the status;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl status mongod<\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\u25cf mongod.service - MongoDB Database Server\n     Loaded: loaded (\/usr\/lib\/systemd\/system\/mongod.service; disabled; preset: enabled)\n     Active: active (running) since Sun 2024-04-21 06:10:47 UTC; 5s ago\n       Docs: https:\/\/docs.mongodb.org\/manual\n   Main PID: 9888 (mongod)\n     Memory: 72.5M (peak: 73.0M)\n        CPU: 463ms\n     CGroup: \/system.slice\/mongod.service\n             \u2514\u25009888 \/usr\/bin\/mongod --config \/etc\/mongod.conf\n\nApr 21 06:10:47 noble-numbat systemd[1]: Started mongod.service - MongoDB Database Server.\nApr 21 06:10:47 noble-numbat mongod[9888]: {\"t\":{\"$date\":\"2024-04-21T06:10:47.606Z\"},\"s\":\"I\",  \"c\":\"CONTROL\",  \"id\":7484500, \"ctx\":\"main\",\"msg\":\"Environment variable MONGODB_CONF\n<\/code><\/pre>\n\n\n\n<p>To enable it to start on boot;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl enable mongod<\/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\">sudo systemctl restart mongod<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl stop mongod<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"connecting-to-mongo-db-on-ubuntu\">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\">sudo apt install net-tools<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">ss -altnp | grep :27<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">LISTEN 0      4096       127.0.0.1:27017      0.0.0.0:*    users:((\"mongod\",pid=9888,fd=13))<\/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\">mongosh<\/pre>\n\n\n\n<p>Or;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mongosh \"mongodb:\/\/localhost:27017\"<\/code><\/pre>\n\n\n\n<p>The command above will launch an interactive MongoDB shell;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>Current Mongosh Log ID:\t6624af029b974a7352c934dc\nConnecting to:\t\tmongodb:\/\/127.0.0.1:27017\/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.4\nUsing MongoDB:\t\t7.0.8\nUsing Mongosh:\t\t2.2.4\n\nFor mongosh info see: https:\/\/docs.mongodb.com\/mongodb-shell\/\n\n\nTo help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https:\/\/www.mongodb.com\/legal\/privacy-policy).\nYou can opt-out by running the disableTelemetry() command.\n\n------\n   The server generated these startup warnings when booting\n   2024-04-21T06:10:47.674+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http:\/\/dochub.mongodb.org\/core\/prodnotes-filesystem\n   2024-04-21T06:10:48.114+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted\n------\n\ntest>\n<\/code><\/pre>\n\n\n\n<p>By default, <strong>mongosh<\/strong> prompt will show the current default database (<strong>test<\/strong>, for example above). You can <a href=\"https:\/\/www.mongodb.com\/docs\/mongodb-shell\/reference\/customize-prompt\/\" target=\"_blank\" rel=\"noreferrer noopener\">customize<\/a> the shell prompt to your liking.<\/p>\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\">help<\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>test> help\n\n  Shell Help:\n\n    use                                        Set current database\n    show                                       'show databases'\/'show dbs': Print a list of all available databases.\n                                               'show collections'\/'show tables': Print a list of all collections for current database.\n                                               'show profile': Prints system.profile information.\n                                               'show users': Print a list of all users for current database.\n                                               'show roles': Print a list of all roles for current database.\n                                               'show log <type>': log for current connection, if type is not set uses 'global'\n                                               'show logs': Print all logs.\n\n    exit                                       Quit the MongoDB shell with exit\/exit()\/.exit\n    quit                                       Quit the MongoDB shell with quit\/quit()\n    Mongo                                      Create a new connection and return the Mongo object. Usage: new Mongo(URI, options [optional])\n    connect                                    Create a new connection and return the Database object. Usage: connect(URI, username [optional], password [optional])\n    it                                         result of the last line evaluated; use to further iterate\n    version                                    Shell version\n    load                                       Loads and runs a JavaScript file into the current shell environment\n    enableTelemetry                            Enables collection of anonymous usage data to improve the mongosh CLI\n    disableTelemetry                           Disables collection of anonymous usage data to improve the mongosh CLI\n    passwordPrompt                             Prompts the user for a password\n    sleep                                      Sleep for the specified number of milliseconds\n    print                                      Prints the contents of an object to the output\n    printjson                                  Alias for print()\n    convertShardKeyToHashed                    Returns the hashed value for the input using the same hashing function as a hashed index.\n    cls                                        Clears the screen like console.clear()\n    isInteractive                              Returns whether the shell will enter or has entered interactive mode\n\n  For more information on usage: https:\/\/docs.mongodb.com\/manual\/reference\/method\n<\/code><\/pre>\n\n\n\n<p>And that is it. You can now start using your MongoDB database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"uninstall-mongo-db-ce-on-ubuntu-24-04\">Uninstall MongoDB CE on Ubuntu 24.04<\/h2>\n\n\n\n<p>If for some reasons you want to uninstall MongoDB and remove it completely on Ubuntu 24.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\">sudo systemctl stop mongod<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt remove --purge --auto-remove mongodb-org<\/pre>\n\n\n\n<p>Remove MongoDB databases;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo rm -rf \/var\/lib\/mongodb<\/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\" id=\"reference\">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\" id=\"further-reading\">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","protected":false},"excerpt":{"rendered":"<p>In this tutorial to learn how to easily install MongoDB on Ubuntu 24.04. According to MongoDB page, &#8220;MongoDB is a general purpose, document-based, distributed database<\/p>\n","protected":false},"author":10,"featured_media":22228,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,299,959],"tags":[7454,961,7396],"class_list":["post-22224","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-database","category-mongodb","tag-install-mongodb","tag-mongodb","tag-ubuntu-24-04","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\/22224"}],"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\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=22224"}],"version-history":[{"count":8,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/22224\/revisions"}],"predecessor-version":[{"id":22762,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/22224\/revisions\/22762"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/22228"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=22224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=22224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=22224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}