Skip to content
Follow
Ubuntu Linux

How to install and configure Memcached on Ubuntu 24.04

Richard
Written by
Richard
May 30, 2024 Updated Sep 15, 2026 4 min read
Memcached featured image
Memcached featured image

Memcached speeds up web apps on Ubuntu 24.04 by storing data in your computer memory instead of slow storage disks. This free caching tool keeps information your website uses often, such as database lookups, right in the server RAM so pages load much faster.

Advertisement

Installing version 1.6.21 or newer gets the system running on your server. You can then change its settings to match what your web apps need.

⚡ Quick Answer

Install Memcached with `sudo apt install memcached libmemcached-tools`. Start and enable the service using `sudo systemctl start memcached` and `sudo systemctl enable memcached`. Configure settings in `/etc/memcached.conf` and restart the service to apply changes.

Advertisement

Install and configure Memcached on Ubuntu

To install Memcached Ubuntu 24.04 on your server, open your terminal and update your package list by running sudo apt update. Next, install Memcached by typing sudo apt install memcached. This background service speeds up your web applications by caching database queries and data in the system memory so your server responds faster.

You can install Memcached on Ubuntu by using the command below.

sudo apt update
sudo apt install memcached libmemcached-tools

Once Memcached is installed, use this command to verify the installed version.

memcached --version

You should see an output similar to the one below.

Advertisement
memcached 1.6.24

On Ubuntu Linux, systemd starts and manages the Memcached service. Use the following command to start, enable, and check the service's status.

To start the Memcached service, run this command:

sudo systemctl start memcached

To enable the Memcached service to start after the system reboots automatically, run this command:

sudo systemctl enable memcached

To check the status of the Memcached service, run this command:

Advertisement
sudo systemctl status memcached

You should see an output similar to the one below:

● memcached.service - memcached daemon
Loaded: loaded (/usr/lib/systemd/system/memcached.service; enabled; preset: enable>
Active: active (running) since Thu 2024-05-30 09:36:26 CDT; 34s ago
Docs: man:memcached(1)
Main PID: 4246 (memcached)
Tasks: 10 (limit: 4561)
Memory: 2.1M (peak: 2.4M)
CPU: 70ms
CGroup: /system.slice/memcached.service
└─4246 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -l ::1 ->
May 30 09:36:26 Ubuntu2404 systemd[1]: Started memcached.service - memcached daemon.

Configure Memcached on Ubuntu

💡TipThe file's default settings should be good enough for most environments and applications.

The file's default settings should be good enough for most environments and applications. However, for more advanced settings, open the file and make the changes you want to apply to your environment.

First, run this command to open the Memcached configuration file.

Advertisement
sudo nano /etc/memcached.conf
⚠️WarningFor example, Memcached listens on the server’s local IP address (127.0.0.1).

For example, Memcached listens on the server’s local IP address (127.0.0.1). If you want it to listen only on a different IP, edit the lines in the file and replace the IP address and/or port number.

# Default connection port is 11211
-p 11211

# Run the daemon as root. The start-memcached will default to running as root if no
# -u command is present in this config file
-u memcache
# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.
-l 127.0.0.1

Save the file and exit. Then, restart Memcached services to apply the changes.

Enable Memcached support for other applications

You can install tools to enable Memcached support for PHP, Python, Perl, and others.

Enable PHP support

To enable Memcached PHP support, run this command:

Advertisement
sudo apt install php-memcached
sudo phpenmod memcached

Enable Python support

To enable Memcached Python support, run this command:

sudo apt install python3-pymemcache

Enable Perl support

To enable Memcached Perl support, run this command:

sudo apt install libcache-memcached-libmemcached-perl

Access Memcached CLI

sudo apt install telnet

Once Telnet is installed, use the command below to access Memcached.

Advertisement
telnet localhost 11211

Run the stats command to get an overview of Memcached content.

stats

You should see an output similar to the one below.

STAT pid 4246
STAT uptime 1172
STAT time 1717080956
STAT version 1.6.24
STAT libevent 2.1.12-stable
STAT pointer_size 64
STAT rusage_user 0.315977
STAT rusage_system 0.157988
STAT max_connections 1024
STAT curr_connections 2
STAT total_connections 3
STAT rejected_connections 0
STAT connection_structures 3
STAT response_obj_oom 0
STAT response_obj_count 1
STAT response_obj_bytes 16384
STAT read_buf_count 2
STAT read_buf_bytes 32768
STAT read_buf_bytes_free 0
...................

Quit the CLI.

quit

That should do it!

Conclusion:

  • Memcached is a powerful open-source, high-performance distributed memory caching system that can significantly enhance the performance and scalability of dynamic database-driven websites.
  • By caching data and objects in RAM, Memcached minimizes the need to read from external data sources, optimizing web application performance and reducing database load.
  • Ubuntu 24.04's installation and configuration process is straightforward, and the default settings are suitable for most environments and applications.
  • Enabling Memcached support for PHP, Python, and Perl and accessing Memcached through the command line interface further extends its usability and benefits for web developers.
  • Implementing Memcached on Ubuntu 24.04 can improve web server performance and provide a superior user experience for website visitors.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

Advertisement

📚 Related Tutorials

How to Install Additional Software on Ubuntu
Ubuntu Linux How to Install Additional Software on Ubuntu
How to Install Python on Ubuntu Linux
Ubuntu Linux How to Install Python on Ubuntu Linux
How to Install PHP on Ubuntu Linux
Ubuntu Linux How to Install PHP on Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

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