install memcached in ubuntu

How to Install Memcached in Ubuntu

Memcached is a popular memory-based caching system that allows you to temporarily store information such as database query results in memory and retrieve it quickly without needing database processing. It reduces load on your database as well as application server, thereby improving website speed and performance. In this article, we will look at how to install Memcached in Ubuntu.

How to Install Memcached in Ubuntu

Here are the steps to install Memcached in Ubuntu.

1. Update system

Open terminal and run the following command to update Ubuntu.

$ sudo apt-get update

2. Install memcached

Run the following commands to install memcached.

$ sudo apt-get install memcached

We will also install libemcached-tools.

$ sudo apt-get install libmemcached-tools

3. Configure Memcached

Open Memcached configuration file.

$ sudo vi /etc/memcached.conf

Inspect -l parameter and ensure that its value is or localhost.


Also, inspect -m parameter and ensure its value is at least 1GB to allocate 1GB space for Memcached objects. You may modify it as per your requirement.

Save and exit the file.

Restart Memcached.

$ sudo service memcached restart

4. Verify Memcached

Run netestat command to ensure that Memcached is running on port 11211 on your machine.

$ sudo netstat -plunt

You should see the following output.

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
. . .
tcp        0      0*               LISTEN      2383/memcached
. . .

5. Connect to Memcached

We have installed Memcached server in the above steps. You may need a Memcached client to communicate with this server and be able to easily access, monitor its performance. There are Memcached client libraries written in all popular languages. You can install them with the following command


If you want to use Memcached as a caching system for popular PHP frameworks such as WordPress, Magento, Drupal, Joomla, you will need to install php-memcached.

$ sudo apt install php-memcached

Once you have installed Memcached client library for PHP, you can verify it by opening php_info() file.


There are several python client libraries available to work with Memcached server. You can install them using pip utility.

$ sudo pip install pymemcache
$ pip install python-memcached

That’s it. In this article, we have seen how to install & configure Memcached in Ubuntu. To learn more, you can refer to its documentation.

Memcached is a useful caching system for websites and applications. It improves website performance by storing frequently accessed information in memory and retrieving it without sending request to application server, thereby reducing server load.

Also read:

NGINX Block URL Access
How to Resize Partition without Data Loss
How to List Directories & Subdirectories in Linux
How to Prevent Cross-Server Scripting in PHP/Apache
Shell Script to Replace Text in File

Leave a Reply

Your email address will not be published. Required fields are marked *