{"id":5461,"date":"2024-09-30T18:32:08","date_gmt":"2024-09-30T13:02:08","guid":{"rendered":"https:\/\/www.veeble.org\/kb\/?p=5461"},"modified":"2025-04-04T12:39:46","modified_gmt":"2025-04-04T07:09:46","slug":"how-to-install-memcached-on-ubuntu","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/how-to-install-memcached-on-ubuntu\/","title":{"rendered":"How to Install Memcached on Ubuntu"},"content":{"rendered":"\n<p>Memcached is a high-performance, distributed memory object caching system that enhances web application speed by reducing the load on databases. It stores frequently accessed data in memory, making it readily available for subsequent requests. Whether you&#8217;re managing a large-scale website or working on a small project, using Memcached on Ubuntu(or any linux VPS) can help optimize performance and reduce latency.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"424\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a-1024x424.jpg\" alt=\"Install Memcached on Ubuntu\" class=\"wp-image-5719\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a-1024x424.jpg 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a-300x124.jpg 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a-768x318.jpg 768w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a-1536x635.jpg 1536w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a-2048x847.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>This guide provides a comprehensive step-by-step tutorial on how to install and configure Memcached on an Ubuntu server.<\/p>\n\n\n\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-08da81b4      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable Of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#advantages-of-memcached\" class=\"uagb-toc-link__trigger\">Advantages of Memcached<\/a><li class=\"uagb-toc__list\"><a href=\"#prerequisites\" class=\"uagb-toc-link__trigger\">Prerequisites<\/a><li class=\"uagb-toc__list\"><a href=\"#steps-to-install-memcached-on-ubuntu\" class=\"uagb-toc-link__trigger\">Steps to install Memcached on Ubuntu<\/a><li class=\"uagb-toc__list\"><a href=\"#how-to-test-memcached-on-ubuntu\" class=\"uagb-toc-link__trigger\">How to Test Memcached on Ubuntu<\/a><li class=\"uagb-toc__list\"><a href=\"#auto-start-memcached-on-boot-optional\" class=\"uagb-toc-link__trigger\">Auto-Start Memcached on Boot (Optional)<\/a><li class=\"uagb-toc__list\"><a href=\"#what-port-does-memcached-use-by-default\" class=\"uagb-toc-link__trigger\">What port does Memcached use by default??<\/a><li class=\"uagb-toc__list\"><a href=\"#conclusion\" class=\"uagb-toc-link__trigger\">Conclusion<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#boost-your-website-speed\" class=\"uagb-toc-link__trigger\">Boost Your Website Speed<\/a><\/ul><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n<h2 class=\"wp-block-heading\" id=\"advantages-of-memcached\">Advantages of Memcached<\/h2>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Improved Performance<\/strong>: <a href=\"https:\/\/en.wikipedia.org\/wiki\/Memcached\" target=\"_blank\" rel=\"noopener\">Memcached <\/a>stores frequently accessed data in memory (RAM), reducing the need to query the database repeatedly. This significantly improves the speed of data retrieval, making applications faster and more responsive.<\/li>\n\n\n\n<li><strong>Scalability<\/strong>: Memcached can handle a large volume of requests and scale horizontally across multiple servers.<\/li>\n\n\n\n<li><strong>Reduced Database Load<\/strong>: By caching data, Memcached reduces the number of queries sent to the database. This decreases the load on the database server, preventing bottlenecks during peak traffic and improving overall system stability.<\/li>\n\n\n\n<li><strong>Efficient Memory Usage<\/strong>: Memcached uses a very efficient memory management system. It stores data in a key-value format, using dynamic memory allocation to avoid unnecessary memory waste.<\/li>\n<\/ul>\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites<\/h2>\n\n\n<ul class=\"wp-block-list\">\n<li>A linux VPS.<\/li>\n\n\n\n<li>A user with sudo privilege.<\/li>\n<\/ul>\n\n\n<h2 class=\"wp-block-heading\" id=\"steps-to-install-memcached-on-ubuntu\">Steps to install Memcached on Ubuntu<\/h2>\n\n\n<p class=\"has-medium-font-size\"><strong>1: Update Your System<\/strong><\/p>\n\n\n\n<p>It&#8217;s always recommended to update your system&#8217;s package list before starting any new installation to avoid compatibility issues. Run the following command to update the package list:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update<\/code><\/pre>\n\n\n\n<p>This will fetch the latest information about available software packages.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>2: Install Memcached<\/strong><\/p>\n\n\n\n<p>Once the system is updated, you can install Memcached and the <code>libmemcached-tools<\/code>, a set of utilities used for interacting with Memcached, using the command below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install memcached libmemcached-tools<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>3: Verify Memcached Installation<\/strong><\/p>\n\n\n\n<p>After the installation is complete, you can verify that Memcached is installed and running by checking its status:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl status memcached<\/code><\/pre>\n\n\n\n<p>If Memcached is active, you should see an output indicating it is running.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>4: Configure Memcached<\/strong><\/p>\n\n\n\n<p>By default, Memcached is configured to listen on <code>localhost<\/code> (127.0.0.1) on port 11211. This configuration works for local caching only. If you need to allow remote access or customize settings like memory usage, you can modify the configuration file located at <code>\/etc\/memcached.conf<\/code>.<\/p>\n\n\n\n<p>To edit the configuration, open the file in a text editor:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/memcached.conf<\/code><\/pre>\n\n\n\n<p><strong>Key Configurations:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Memory Usage<\/strong>: Adjust the memory limit by changing the value after the <code>-m<\/code> option (default is 64MB).<br>Example:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>-m 128<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Listen Address<\/strong>: To allow external access, change the listening address from <code>127.0.0.1<\/code> to <code>0.0.0.0<\/code>.<\/li>\n\n\n\n<li><strong>Port<\/strong>: Memcached listens on port 11211 by default, but you can change this if needed by modifying the <code>-p<\/code> option.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>-p 11212<\/code><\/pre>\n\n\n\n<p>After making the necessary changes, save and close the file .<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>5: Restart Memcached Service<\/strong><\/p>\n\n\n\n<p>Once you\u2019ve made changes to the configuration, restart Memcached to apply the new settings:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart memcached<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>6: Firewall Configuration (Optional)<\/strong><\/p>\n\n\n\n<p>If your server\u2019s firewall is enabled and you need to allow remote access to Memcached, you must open the Memcached port (11211 by default).<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-test-memcached-on-ubuntu\">How to Test Memcached on Ubuntu<\/h2>\n\n\n<p>You can test if Memcached is working correctly by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"stats settings\" | nc localhost 11211<\/code><\/pre>\n\n\n\n<p>This will return detailed statistics about your Memcached setup, confirming that it is operational.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"autostart-memcached-on-boot-optional\">Auto-Start Memcached on Boot (Optional)<\/h2>\n\n\n<p>To ensure Memcached starts automatically after a reboot, you can enable it by running.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl enable memcached<\/code><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"what-port-does-memcached-use-by-default\">What port does Memcached use by default??<\/h2>\n\n\n<p>Memcached listens on port 11211 by default, but you can change this if needed by editing the configuration file \/etc\/memcached.conf.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n<p>Memcached is a powerful and efficient caching tool that can significantly speed up your website or application by reducing the load on your database. By following this guide, you have successfully installed and configured Memcached on Ubuntu, optimized for your specific needs. Make sure to monitor your caching performance regularly and adjust memory settings to best suit your workload.<\/p>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-c4f1e10c wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Boost Your Website Speed<\/h3><p class=\"uagb-cta__desc\">Supercharge your site with our high-performance Managed VPS. Optimized for speed.<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/managed-vps\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">View Pricing<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Memcached is a high-performance, distributed memory object caching system that enhances web application speed by reducing the load on databases. It stores frequently accessed [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":5719,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5],"tags":[],"class_list":["post-5461","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a.jpg",2202,911,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a-300x124.jpg",300,124,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a-768x318.jpg",768,318,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a-1024x424.jpg",1024,424,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a-1536x635.jpg",1536,635,true],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-09-30-15.50.05-A-detailed-diagram-showing-Memcached-architecture.-The-diagram-should-include-Memcached-server-in-the-center-with-arrows-connecting-to-clients-web-a-2048x847.jpg",2048,847,true]},"uagb_author_info":{"display_name":"Nayana Nair","author_link":"https:\/\/www.veeble.com\/kb\/author\/nayana\/"},"uagb_comment_info":0,"uagb_excerpt":"Memcached is a high-performance, distributed memory object caching system that enhances web application speed by reducing the load on databases. It stores frequently accessed [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/5461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=5461"}],"version-history":[{"count":5,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/5461\/revisions"}],"predecessor-version":[{"id":8478,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/5461\/revisions\/8478"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/5719"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=5461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=5461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=5461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}