Guides 11792 Published by

The guide explains how to install Memcached on Ubuntu 22.04 by first updating the system and then installing the memcached package from the universe repository, adding libmemcached‑dev only if client libraries are needed. It walks through editing /etc/memcached.conf to set memory limits, listening address, and connection parameters, and shows how to enable and start the service with systemd while noting that changes require a restart. A quick connectivity test with ss or telnet confirms Memcached is running on port 11211, and the article lists common issues such as port conflicts, insufficient RAM, and firewall restrictions. In short, it offers a concise, step‑by‑step method to get a reliable caching daemon up and running so that web applications can reduce database load and speed up page responses.



Install Memcached on Ubuntu 22.04 LTS

A quick guide to getting Memcached up and running on the latest LTS release without wasting time chasing broken dependencies or mis‑configured services.

Why you’ll actually need this

When a PHP, Ruby, or Python app starts to choke on repeated database hits, turning Memcached on can shave seconds off page loads. On Ubuntu 22.04, the package is in the universe repo, so installing it straight from the command line is all that’s required—no compiling, no external PPAs.

Update the system first
sudo apt update && sudo apt upgrade -y

Fetching fresh metadata guarantees you’ll pull the newest build of Memcached. Skipping this step often results in a broken dependency graph when newer libraries are pulled by other packages later on.

Install the core package
sudo apt install memcached libmemcached-dev -y

libmemcached-dev is optional unless you plan to compile client libraries; it just makes life easier for developers. The binary installs under /usr/sbin/memcached.

Configure Memcached’s listening port and memory

The default config file sits at /etc/memcached.conf. Open it with a text editor:

sudo nano /etc/memcached.conf

Inside, locate the -m flag (memory in megabytes) and adjust it to match your server’s RAM. For a small dev box, 64 MB is plenty; on production you might set 512 MB or more.

Also look for -l. By default Memcached listens on all interfaces (0.0.0.0). That’s fine locally but risky if the machine is exposed to the internet—change it to 127.0.0.1 unless an external app needs direct access.

Adjust daemon options for performance

A few flags make a noticeable difference:

  • -p 11211 – default port; keep it unless you know another service will clash.
  • -u memcache – runs under a dedicated user, limiting damage if the cache is compromised.
  • -c 1024 – number of concurrent connections. The default is usually too low for busy sites.

Add or tweak these lines in /etc/memcached.conf. Remember: every change requires a restart to take effect.

Enable and start the service
sudo systemctl enable memcached
sudo systemctl start memcached

systemd will now manage Memcached, restarting it after reboots or crashes. Verify it's listening:

ss -tnlp | grep memcached

You should see a line like LISTEN 0 128 127.0.0.1:11211.

Quick sanity check with telnet
telnet 127.0.0.1 11211

If the connection opens, hit CTRL‑C to exit. A successful handshake proves the daemon is reachable.

Common gotchas and how to sidestep them

  • Port conflict: If another service already uses port 11211, Memcached will silently fail to start. Run sudo ss -tnlp | grep :11211 before installing.
  • Insufficient memory: On a minimal VM with 1 GB RAM, allocating 512 MB to Memcached can starve the OS and other services. Keep an eye on /var/log/syslog; kernel OOM killer messages usually point to this issue.
  • Firewall rules: Ubuntu’s default UFW may block port 11211. If you need external access (rare), allow it with sudo ufw allow 11211/tcp.
Wrap‑up

Installing Memcached on Ubuntu 22.04 is a one‑liner followed by a few tweaks. Once it’s running, apps that can cache data will feel lighter, faster, and happier.