How to install Memcached on Ubuntu 20.04

s2 0

Memcached is a free, open source, high performance, in-memory key-value data store. It is commonly used to speed up applications by caching various objects from the results of API and database calls.

This article shows how to install and configure Memcached on Ubuntu 20.04.

Install Memcached

The Memcached package is included in the standard Ubuntu 20.04 repositories. To install it, enter the following command as root or user with sudo rights:

sudo apt updatesudo apt install memcached libmemcached-tools
the libmemcached-tools Package contains command line utilities that you can use to administer the Memcached server.

When the installation is complete, the Memcached service will start automatically. Enter the following to check the status of the service:

sudo systemctl status memcached

The output looks something like this:

● memcached.service - memcached daemon
     Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2020-07-13 19:32:01 UTC; 23s ago

That’s it, you’ve installed Memcached on your Ubuntu 20.04 server and you’re ready to use it.

Configure Memcached

Memcached options can be configured in the menu /etc/memcached.conf File. By default, memcached is set to only listen on localhost.

The default configuration settings are sufficient for most users.

Remote access

If the client that connects to memcached is running on the same host, you should not allow remote access.

If configured incorrectly, Memcached can be used to carry out a distributed denial of service (DDoS) attack. To allow remote access to the Memcached server, you need to configure the firewall and only open the Memcached UDP port 11211 from trusted clients.

The following example assumes that you want to connect to the Memcached server over a private network. The IP of the Memcached server is, and the client’s IP address is

The first step is to edit the Memcached configuration and set the service to monitor the server’s private network interface:

To do this, open the memcached.conf Configuration file:

sudo nano /etc/memcached.conf

Find the line that starts with -l and replace with the server IP address


Restart the Memcached service for the changes to take effect:

sudo systemctl restart memcached

Once the service is configured, the next step is to open the memcached port in the firewall.

sudo ufw allow from to any port 11211

Connect to Memcached

There are many implementations of Memcached clients written for different programming languages.


In order to use Memcached as a caching database for your PHP application like WordPress, Drupal, Joomla or Magento, you need to have the php-memcached Renewal:

sudo apt install php-memcached


There are several Python libraries for interacting with Memcache. You can install your preferred library using pip:

pip install pymemcache
pip install python-memcached


We showed you how to install Memcached on Ubuntu 20.04. More information on this topic can be found at Memcached Wiki

If you have any questions or feedback, feel free to comment below.