How to Install Memcached on Ubuntu 26.04, 24.04 and 22.04

Install Memcached on Ubuntu 26.04, 24.04 and 22.04 via APT or source build. Configure memory limits, security, PHP and Python clients.

Last updatedAuthorJoshua JamesRead time13 minGuide typeUbuntu

Repeated database lookups become expensive once a site starts serving real traffic, and Memcached gives Ubuntu servers a small, fast RAM cache for those hot reads. You can install Memcached on Ubuntu 26.04, 24.04, and 22.04 from Ubuntu’s repositories for a service-managed setup, or compile the current upstream release when you need custom build flags such as SASL support.

The APT package is the safer default for production because Ubuntu starts the service automatically and keeps the package updated through normal system upgrades. Source compilation is useful when your application needs a newer upstream build than your Ubuntu release ships.

These steps apply to Ubuntu 26.04 (resolute), Ubuntu 24.04 (noble), and Ubuntu 22.04 (jammy). Commands are identical across releases unless a section calls out a version-specific difference.

Install Memcached on Ubuntu

Install Memcached with APT

Update Package Index

Update your package lists and process any pending upgrades before installing Memcached:

sudo apt update && sudo apt upgrade

These commands use sudo for system-level package and service changes. If your account does not have sudo rights yet, follow the Ubuntu sudoers guide to add a user to sudoers on Ubuntu.

Install Memcached from Ubuntu Repositories

Install the Memcached server and optional command-line tools:

sudo apt install memcached libmemcached-tools

The libmemcached-tools package provides utilities like memstat for monitoring cache statistics and memflush for clearing all cached data. These tools are optional but useful for troubleshooting and maintenance.

Verify Memcached Installation

Confirm the installation by checking the version:

memcached -V

Ubuntu 26.04 currently returns:

memcached 1.6.40

Ubuntu 24.04 returns memcached 1.6.24, while Ubuntu 22.04 returns memcached 1.6.14. The APT package also enables Memcached as a systemd service, so it starts automatically at boot and is already running after installation.

Compile Memcached from Source

Compile from source when you need the latest upstream release, currently 1.6.41, or custom build options like SASL authentication. Use either the APT package or the source-built service, not both, because both use port 11211 and the memcached service name.

Install Build Dependencies

Install the compiler, download tools, and development headers needed to compile Memcached:

sudo apt install build-essential libevent-dev libc6-dev curl wget ca-certificates

The libevent-dev package provides the event notification library that Memcached uses for network connections. If you want SASL authentication support, also install the SASL development headers before running configure:

sudo apt install libsasl2-dev

Download and Verify Memcached Source

Create a dedicated build directory, set the current stable version, and download the source archive with its SHA1 checksum file:

mkdir -p ~/memcached-build
cd ~/memcached-build
MEMCACHED_VERSION="1.6.41"
wget "https://memcached.org/files/memcached-${MEMCACHED_VERSION}.tar.gz"
wget "https://memcached.org/files/memcached-${MEMCACHED_VERSION}.tar.gz.sha1"

Verify the download before extracting it:

sha1sum -c "memcached-${MEMCACHED_VERSION}.tar.gz.sha1"

A valid archive returns:

./memcached-1.6.41.tar.gz: OK

Unpack the Memcached Source Archive

Extract the compressed archive and enter the source directory:

tar -xzf "memcached-${MEMCACHED_VERSION}.tar.gz"
cd "memcached-${MEMCACHED_VERSION}"

Configure the Build

Prepare the build. The --prefix=/usr/local option installs the source-built binary under /usr/local/bin, which normally takes precedence over Ubuntu’s packaged binary on your PATH:

./configure --prefix=/usr/local

If you installed libsasl2-dev and want SASL authentication, add the flag:

./configure --prefix=/usr/local --enable-sasl

The configure script checks for required libraries and generates the Makefile. Look for lines confirming libevent detection:

checking for libevent directory... (system)
checking for library containing event_base_new... -levent
configure: creating ./config.status
config.status: creating Makefile

Compile the Memcached Source Code

Compile the source using all available CPU cores to speed up the build:

make -j$(nproc)

The -j$(nproc) flag runs multiple compilation jobs in parallel. On a typical server, compilation completes in under a minute.

After compilation, verify the binary was built correctly from the build directory:

./memcached -V
memcached 1.6.41

Install the Compiled Binaries

Install the compiled binary system-wide:

sudo make install

Verify Installation (Source Method)

Confirm the installed version is accessible from your PATH:

memcached -V
memcached 1.6.41

You can also verify the binary location to confirm the source-compiled version takes precedence:

which memcached
/usr/local/bin/memcached

Set Up a systemd Service (Source Install)

Source-compiled Memcached requires a systemd unit file to manage it as a service. The APT package includes a pre-configured unit with security hardening; follow these steps to create a similar setup for your source build.

Create a Dedicated User and Group

Create a system account without login access to run the Memcached daemon if the account does not already exist:

if ! id -u memcache >/dev/null 2>&1; then
  sudo useradd -r -s /usr/sbin/nologin -U -M memcache
fi

The command checks for an existing account first. When creation is needed, the flags create a system user (-r) with no login shell (-s /usr/sbin/nologin), a matching group (-U), and no home directory (-M).

Create the Service File

Create the systemd unit file:

sudo nano /etc/systemd/system/memcached.service

Add the following configuration. This includes security hardening directives similar to the APT package’s unit file. Adjust the ExecStart flags (-m for memory, -c for max connections, -t for threads) to match your server resources:

[Unit]
Description=Memcached In-Memory Object Cache
After=network.target
Documentation=man:memcached(1)

[Service]
Type=simple
User=memcache
Group=memcache
ExecStart=/usr/local/bin/memcached -u memcache -m 64 -p 11211 -l 127.0.0.1 -c 1024 -t 4
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
LimitNOFILE=65535

# Security hardening
PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
PrivateDevices=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectControlGroups=true
RestrictRealtime=true

[Install]
WantedBy=multi-user.target

The security directives isolate Memcached from the rest of the system: PrivateTmp gives it a private /tmp directory, ProtectSystem mounts system directories read-only, and NoNewPrivileges prevents privilege escalation.

Save and Close the Editor

In nano, press Ctrl+X, then Y, then Enter to save and exit.

Reload systemd and Enable the Service

Reload the systemd configuration to recognize the new unit, then enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable memcached --now

The --now flag combines enabling (auto-start at boot) with immediate startup in one command.

Compare Memcached Versions and Methods on Ubuntu

Ubuntu’s repository package is the best fit for most servers because it installs a ready-made systemd service and receives updates through the normal APT workflow. Source compilation trades that convenience for a newer upstream release and optional compile-time features.

Default Memcached Versions by Ubuntu Release

The default APT package version depends on the Ubuntu release:

Ubuntu ReleaseCodenameAPT Package VersionStandard Support
Ubuntu 26.04resolute1.6.40-1Until May 2031
Ubuntu 24.04noble1.6.24-1build3Until May 2029
Ubuntu 22.04jammy1.6.14-1ubuntu0.1Until May 2027

The Ubuntu Memcached package search shows the archive package, while the official Memcached downloads page lists the current upstream stable release.

Choose an Installation Method

MethodVersion SourceUpdatesBest For
APT packageUbuntu release archiveNormal apt upgrade workflowProduction servers and most deployments
Source buildCurrent upstream stable, 1.6.41 at review timeManual rebuild or update scriptCustom build flags, SASL builds, newer upstream features

If you do not need a specific upstream feature, use the APT package. It avoids PATH conflicts, integrates with Ubuntu’s package database, and keeps service files under package-manager control.

Memcached Service Commands

Ubuntu uses systemd to manage Memcached. These commands work for both APT and source installations (after creating the systemd unit).

Check Service Status

The APT package enables Memcached automatically after installation. Verify the service is running and enabled at boot:

systemctl is-active memcached
systemctl is-enabled memcached

A healthy package install returns:

active
enabled

If the service is not running, start and enable it:

sudo systemctl enable memcached --now

Common Service Commands

Start Memcached manually:

sudo systemctl start memcached

Enable auto-start at boot:

sudo systemctl enable memcached

Stop Memcached:

sudo systemctl stop memcached

Disable auto-start at boot:

sudo systemctl disable memcached

Restart Memcached (required after configuration changes):

sudo systemctl restart memcached

Confirm the Listening Port

Verify Memcached is listening on port 11211:

ss -H -ltn 'sport = :11211'

For APT installs, Ubuntu 26.04 and 24.04 show both IPv4 and IPv6 loopback listeners by default:

LISTEN 0      1024   127.0.0.1:11211 0.0.0.0:*
LISTEN 0      1024       [::1]:11211    [::]:*

Ubuntu 22.04 may show only the IPv4 loopback listener. A source install using the systemd unit in this guide also shows IPv4 loopback only unless you add a second -l ::1 listener. In each case, Memcached is bound to localhost by default and is not reachable from other machines until you deliberately change the listening address.

Configure Memcached

Configuration differs based on your installation method. APT installs use a Debian-style config file parsed by the systemd service wrapper. Source installs pass flags directly in the systemd unit’s ExecStart line.

Memcached has no built-in authentication by default. Exposing it to the internet without additional protection (firewall, SASL) invites abuse. Keep it bound to 127.0.0.1 and ::1 unless you specifically need remote access from trusted networks.

APT Install: Edit /etc/memcached.conf

Open the configuration file:

sudo nano /etc/memcached.conf

The default configuration uses Debian-style flag format. Key settings in a typical production configuration:

# Memory in MB (default: 64)
-m 64

# TCP port (default: 11211)
-p 11211

# Run as this user
-u memcache

# Bind addresses (loopback for security)
-l 127.0.0.1
-l ::1

# Maximum simultaneous connections (default: 1024)
# -c 1024

# Disable UDP (reduces attack surface)
# -U 0

# Log file location
logfile /var/log/memcached.log

Ubuntu 26.04 and 24.04 include both loopback bindings in the default file. Ubuntu 22.04 defaults to 127.0.0.1; add -l ::1 only if your local applications need IPv6 loopback access.

Listening Address

Keep Memcached bound to loopback for same-server application use. Only change the -l parameter if a trusted remote application server must connect, and protect that listener with a firewall or private network.

Disable UDP

UDP support is disabled by default in recent Memcached versions because it was exploited in amplification attacks. If you’re using an older version, explicitly disable it:

-U 0

Adjust Memory Allocation

The -m flag sets the maximum memory Memcached uses for storing cached items. The default is 64 MB, which is conservative. For a dedicated caching server, increase this based on available RAM:

# Allocate 2 GB for caching
-m 2048

Leave at least 1-2 GB free for the operating system and other processes. Memcached grows to this limit gradually as items are cached; it does not allocate all memory immediately at startup.

Apply Configuration Changes

After editing the configuration, restart Memcached to apply the updates:

sudo systemctl restart memcached

Additional Configuration Options

Beyond basic settings, Memcached offers tuning options for performance and security. Add these flags to /etc/memcached.conf for APT installs or the ExecStart line in your systemd unit for source builds, then restart the service.

For comprehensive documentation on all available options, see the official Memcached documentation.

Specify User

Run Memcached as a dedicated non-root user. The APT package already configures this:

-u memcache

Enable Large Memory Pages

Huge pages can improve performance on systems with large cache allocations by reducing TLB misses. Enable with -L (requires kernel huge pages configured):

-L

Configure Maximum Item Size

The default maximum item size is 1 MB. Increase this if you need to cache larger objects:

# Allow items up to 5 MB
-I 5m

Be aware that very large items can cause memory fragmentation.

Set Thread Count

Memcached defaults to 4 threads. Match this to your available CPU cores for high-throughput workloads:

# Use 8 threads
-t 8

Adjust Idle Timeout

Set idle connection timeout (in seconds) to close abandoned client connections:

-o idle_timeout=600

Enable SASL Authentication

SASL provides username/password authentication. Enable with -S (requires building with --enable-sasl or using the APT package with SASL libraries installed):

-S

After any configuration changes, restart Memcached:

sudo systemctl restart memcached

Secure Memcached with UFW

Memcached binds to localhost by default and requires no firewall rules for local use. If you expose it to a network for clustering or remote clients, restrict access with UFW (Uncomplicated Firewall). For a broader overview, see the guide to installing and configuring UFW firewall on Ubuntu.

Check UFW Status

Check if UFW is installed and active:

sudo ufw status

If UFW is not installed:

sudo apt install ufw

Allow SSH Before Enabling UFW

Before enabling UFW, allow SSH to avoid locking yourself out of a remote server:

sudo ufw allow OpenSSH

Enabling UFW without an SSH rule immediately disconnects remote sessions. Always add your management access rule first.

Create UFW Rules for Memcached

Allow only trusted sources to connect to Memcached.

Allow a Single IP

Replace 192.168.1.100 with the trusted client’s IP address:

sudo ufw allow proto tcp from 192.168.1.100 to any port 11211

Allow a Subnet (Cluster)

For internal clusters, allow an entire subnet. Replace 10.0.0.0/24 with your network range:

sudo ufw allow proto tcp from 10.0.0.0/24 to any port 11211

Enable UFW

With your rules configured, enable the firewall:

sudo ufw enable

If UFW was already active, reload it to apply new rules:

sudo ufw reload

Verify UFW Rules

List active rules to confirm your configuration:

sudo ufw status numbered

Example output with SSH and Memcached rules:

Status: active

     To                         Action      From
     --                         ------      ----
[ 1] OpenSSH                    ALLOW IN    Anywhere
[ 2] 11211/tcp                  ALLOW IN    10.0.0.0/24

The numbered flag shows rule numbers, which you need if you want to delete a specific rule later (e.g., sudo ufw delete 2). For more firewall management options, see the Ubuntu firewall management guide.

Install Memcached Language Libraries

Applications connect to Memcached through client libraries. The sections below install packages for PHP, Python, and Perl. Some client packages, including php-memcached and libcache-memcached-libmemcached-perl, come from Ubuntu’s universe component. If APT cannot locate them, use the Ubuntu components guide to enable Universe on Ubuntu, then repeat the install command.

PHP Memcached Extension

PHP applications such as WordPress, Laravel, and Drupal use the php-memcached extension to connect to a Memcached server.

Install PHP Memcached Extension

Install the PHP CLI and Memcached extension package:

sudo apt install php-cli php-memcached

Verify PHP can load the extension:

php -m | grep -i '^memcached$'

A working CLI check returns:

memcached

Restart the PHP runtime your site actually uses after installing the extension. Apache deployments usually restart apache2:

sudo systemctl restart apache2

For Nginx with PHP-FPM, restart the installed FPM service instead:

PHP_FPM_SERVICE=$(systemctl list-unit-files 'php*-fpm.service' --no-legend | awk '{print $1}' | head -n 1)
if [ -n "$PHP_FPM_SERVICE" ]; then
  sudo systemctl restart "$PHP_FPM_SERVICE"
else
  echo "No PHP-FPM service found."
fi

For broader PHP package choices, see the PHP on Ubuntu installation guide. For WordPress sites, object-cache plugins such as W3 Total Cache can use Memcached at 127.0.0.1:11211. Keep the Memcached server local unless you have a private application network and firewall rules in place.

Python

Install a Python Memcached client library:

sudo apt install python3-pymemcache

The pymemcache library is a modern, pure-Python client maintained by Pinterest.

Perl

Install the Perl Memcached client:

sudo apt install libcache-memcached-libmemcached-perl

Access Memcached from the Command Line

You can interact with Memcached directly for testing and diagnostics using Telnet or netcat. This is useful for verifying connectivity, checking cache statistics, and debugging.

Connect with Telnet

Connect to the local Memcached instance:

telnet localhost 11211

On success:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

If Telnet is not installed:

sudo apt install telnet

For more Telnet options, see the Telnet installation guide for Ubuntu.

Connect with Netcat

Netcat (nc) works without an interactive prompt, making it useful for scripts. Install the OpenBSD flavor if needed:

sudo apt install netcat-openbsd

Send a stats command and exit:

printf 'stats\r\nquit\r\n' | nc localhost 11211

Retrieve Statistics

Once connected via Telnet, run stats for a cache summary:

stats

This displays uptime, cache hit/miss counts, current items stored, memory usage, and active connections.

Store a Test Key

Add a small temporary value before testing key retrieval or deletion:

set testkey 0 60 9
test data

Memcached confirms the item was stored:

STORED

Inspect Memory Slabs

Memcached organizes memory into slabs. View slab allocation:

stats slabs

View item counts per slab:

stats items

Inspect Cached Keys for Troubleshooting

Memcached does not provide a reliable production-safe command to list every key. For troubleshooting on a test cache, inspect a specific slab with stats cachedump. The syntax is stats cachedump [slab_id] [limit]; a limit of 0 asks for all items in that slab, not every key in the server:

stats cachedump 1 0

If the test key is in that slab, the response includes an ITEM testkey line followed by END. Empty slabs return only END. Use the slab ID from stats items instead of assuming every key is in slab 1.

Retrieve a Cached Key

Retrieve the test key’s value with get:

get testkey

Example output:

VALUE testkey 0 9
test data
END

Delete a Cached Key

Remove a specific key:

delete testkey

Response:

DELETED

To close the Telnet connection, type quit or press Ctrl+] then type quit.

Troubleshooting

Service Fails to Start

If Memcached fails to start after installation or configuration changes, check the systemd journal for error details:

journalctl -u memcached -e

A common error when using source builds looks like:

memcached.service: Failed at step USER spawning /usr/local/bin/memcached: No such process

This means the memcache user does not exist. Create it before starting the service:

sudo useradd -r -s /usr/sbin/nologin -U -M memcache

Another common cause is including -d (daemonize) in the ExecStart line. The systemd Type=simple expects the process to stay in the foreground; remove -d from your configuration.

Port Already in Use

If Memcached cannot bind to port 11211, another process is using it. Find the conflicting process:

sudo ss -tlnp | grep :11211

Example output showing another Memcached instance:

LISTEN 0      1024       127.0.0.1:11211       0.0.0.0:*    users:(("memcached",pid=2345,fd=26))

Stop the conflicting process or change Memcached’s port in the configuration (-p 11212). If you have both APT and source installs, ensure only one systemd unit is enabled.

Connection Refused from Application

When your application reports connection errors but Memcached appears to be running, verify the service is listening:

systemctl is-active memcached && sudo ss -tlnp | grep memcached

If active but not listening, the process started but failed to bind. Check journal logs for binding errors. If listening but the application cannot connect, verify your application is configured to use 127.0.0.1:11211 (not localhost, which may resolve to IPv6 on some systems).

Test connectivity directly:

printf 'stats\r\nquit\r\n' | nc localhost 11211 | head -5

A working response returns statistics. No response or “Connection refused” indicates a configuration mismatch.

SASL Authentication Not Working

SASL authentication requires explicit compilation support. Check if your Memcached binary includes SASL:

memcached -h 2>&1 | grep -i sasl

If no output appears, SASL is not compiled in. For source builds, reinstall the SASL libraries and recompile:

sudo apt install libsasl2-dev sasl2-bin
cd ~/memcached-build/memcached-1.6.41
./configure --prefix=/usr/local --enable-sasl
make clean && make -j$(nproc)
sudo make install

The APT package supports SASL if the libraries are installed; add -S to the configuration to enable it.

Update Source-Compiled Memcached

If you compiled Memcached from source, use this script to check for updates and recompile when a new version is available. The script detects your installed version, fetches the latest release from memcached.org, and rebuilds only when an update exists.

Create the Update Script

Create a directory for the script and build files:

mkdir -p ~/memcached-build

Create the update script:

cat << 'EOF' | sudo tee /usr/local/bin/memcached-update > /dev/null
#!/usr/bin/env bash
set -euo pipefail

INSTALL_PREFIX="/usr/local"
BUILD_DIR="$HOME/memcached-build"

if [ "$(id -u)" -eq 0 ]; then
  echo "Run this script as a regular user; it will ask for sudo only when installing."
  exit 1
fi

for cmd in curl tar gcc make grep sha1sum nproc; do
  if ! command -v "$cmd" >/dev/null 2>&1; then
    echo "Error: $cmd is required but not installed."
    echo "Run: sudo apt install build-essential libevent-dev curl"
    exit 1
  fi
done

mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"

CURRENT_VERSION="$("${INSTALL_PREFIX}/bin/memcached" -V 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1 || true)"
CURRENT_VERSION="${CURRENT_VERSION:-none}"

echo "Checking for latest version..."
LATEST_URL="$(curl -fsSIL -o /dev/null -w '%{url_effective}' https://memcached.org/latest)"
LATEST_VERSION="$(printf '%s\n' "$LATEST_URL" | grep -oE 'memcached-[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1 || true)"

if [ -z "$LATEST_VERSION" ]; then
  echo "Error: Could not detect latest version from memcached.org/latest"
  exit 1
fi

echo "Current version: $CURRENT_VERSION"
echo "Latest version:  $LATEST_VERSION"

if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then
  echo "Already up to date."
  exit 0
fi

echo "Updating from $CURRENT_VERSION to $LATEST_VERSION..."
rm -rf "memcached-$LATEST_VERSION"

echo "Downloading memcached-$LATEST_VERSION..."
curl -fLO --progress-bar "https://memcached.org/files/memcached-$LATEST_VERSION.tar.gz"
curl -fLO --progress-bar "https://memcached.org/files/memcached-$LATEST_VERSION.tar.gz.sha1"
sha1sum -c "memcached-$LATEST_VERSION.tar.gz.sha1"

tar -xzf "memcached-$LATEST_VERSION.tar.gz"
rm "memcached-$LATEST_VERSION.tar.gz" "memcached-$LATEST_VERSION.tar.gz.sha1"

cd "memcached-$LATEST_VERSION"

echo "Configuring..."
./configure --prefix="$INSTALL_PREFIX"
echo "Compiling..."
make -j"$(nproc)"

echo "Installing (requires sudo)..."
sudo make install

if systemctl is-active --quiet memcached 2>/dev/null; then
  echo "Restarting memcached service..."
  sudo systemctl restart memcached
fi

NEW_VERSION="$("${INSTALL_PREFIX}/bin/memcached" -V | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1)"
echo "Successfully updated to memcached $NEW_VERSION"
EOF
sudo chmod +x /usr/local/bin/memcached-update

Run the Update Script

Since the script is installed to /usr/local/bin, you can run it from any directory:

memcached-update

Example output when already up to date:

Checking for latest version...
Current version: 1.6.41
Latest version:  1.6.41
Already up to date.

When an update is available, the script downloads the new version, compiles it, installs the binary, and restarts the service if it was running.

Avoid automating this with cron. Compilation can fail due to missing dependencies or network issues. Run the script manually so you can monitor the output and address any problems.

Uninstall Memcached

Remove APT Installation

Stop the service and purge the Memcached packages:

sudo systemctl disable memcached --now
sudo apt purge memcached libmemcached-tools

The purge command removes package-owned configuration files under /etc. Confirm the packages are no longer installed:

dpkg -l memcached libmemcached-tools | grep '^ii'

No output means the APT packages are removed. If you installed the optional language client packages from this guide and no longer need them, remove them separately:

sudo apt purge php-memcached python3-pymemcache libcache-memcached-libmemcached-perl

If you want to clean unused dependencies afterward, review the proposed removal list before confirming:

sudo apt autoremove --dry-run

Remove Source Installation

For source-compiled installations, stop the service first:

sudo systemctl disable memcached --now

If the source tree is still present, remove the files installed by make install with the upstream uninstall target:

cd ~/memcached-build/memcached-1.6.41
sudo make uninstall

If the source tree is gone, remove the source-installed files created by this workflow:

sudo rm -f /usr/local/bin/memcached
sudo rm -f /usr/local/share/man/man1/memcached.1

Remove the custom service and update helper:

sudo rm -f /etc/systemd/system/memcached.service
sudo systemctl daemon-reload
sudo rm -f /usr/local/bin/memcached-update

Remove the source-created service account only when no package-managed Memcached install remains:

if id -u memcache >/dev/null 2>&1 && ! dpkg -s memcached >/dev/null 2>&1; then
  sudo userdel memcache 2>/dev/null || true
fi

The next cleanup removes the build directory created by this source workflow. Back up ~/memcached-build first if you modified the source tree or kept local build notes there.

rm -rf ~/memcached-build

Clear the shell command cache and verify the source-built binary is gone:

hash -r
command -v memcached || echo "memcached command not found"
memcached command not found

The cache data stored in Memcached exists only in RAM. When you stop the service, all cached data is immediately lost without needing any additional cleanup.

Compare Memcached and Redis on Ubuntu

Memcached is a volatile key-value cache built for simple, fast lookups. Redis on Ubuntu offers richer data structures, persistence options, pub/sub messaging, and scripting, so it is a better fit when cached data must survive restarts or when the application needs more than basic key-value storage.

Memcached and Redis can run on the same Ubuntu server because they use different default ports, 11211 for Memcached and 6379 for Redis. Make sure the server has enough RAM for both services, your application, and the operating system before enabling both cache layers.

Conclusion

Memcached is running on Ubuntu with a localhost-only listener, systemd service management, and client libraries ready for your application. Keep the listener local for single-server deployments; when remote clients need access, pair the bind-address change with source-limited UFW rules and watch hit rate, evictions, and memory use before raising the cache size.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Verify before posting: