sodcalculator

10 Tech How-To

Install Memcached on Linux: Ubuntu, Debian, and RHEL

Guide 10-41488 · Updated · Step by step

To install Memcached on Linux, use your distribution’s package manager: on Ubuntu or Debian, run sudo apt update followed by sudo apt install memcached; on Fedora or RHEL-family systems, use sudo dnf install memcached. Then start the service, enable it at boot if needed, and check that it is listening only on an appropriate network interface.

What Memcached does

Memcached is an in-memory key-value cache commonly used by applications to keep frequently requested data available without repeatedly querying a database or rebuilding a result. It is a cache, not a durable database: its contents can disappear when the service restarts, memory is reclaimed, or an item expires. Applications must be able to regenerate cached values or fetch them from their underlying source.

Memcached has a client-server design. The server runs as a Linux service and listens for requests; an application connects using a compatible client library. Installing the server alone does not automatically make a website or program use it. You must configure the application with the server address and port, and the application’s client must support Memcached.

Install on Ubuntu or Debian

On a supported Ubuntu or Debian system, open a terminal and run:

  1. sudo apt update refreshes the local package index.
  2. sudo apt install memcached installs the package and its dependencies.
  3. sudo systemctl status memcached checks whether the service is running.

Package installation often starts the service automatically, but verify rather than assume. If it is stopped, run sudo systemctl start memcached. To request automatic startup after a reboot, run sudo systemctl enable memcached. You can combine those actions with sudo systemctl enable --now memcached.

Package names and available versions depend on the distribution release and its configured repositories. Use the package supplied for your operating system unless you have a specific reason to build or install a different version. Avoid mixing packages from unrelated distributions.

Install on Fedora, RHEL, and other distributions

Fedora and many current RHEL-family systems use DNF:

  1. Install with sudo dnf install memcached.
  2. Start it with sudo systemctl start memcached.
  3. Enable it at boot with sudo systemctl enable memcached, or do both with sudo systemctl enable --now memcached.
  4. Check it with sudo systemctl status memcached.

Older systems may use yum rather than dnf; follow the package manager supported by that system. On Arch Linux, the package is commonly installed with sudo pacman -S memcached, then managed through systemd. Package and service names can vary, so confirm with the distribution’s package search and service documentation if a command reports that the package or unit is missing.

Configure and start the service safely

Memcached’s configuration file location and defaults vary by distribution package. Common locations include /etc/memcached.conf and /etc/sysconfig/memcached. Check the service status and package documentation to identify the file used on your machine. Configuration commonly controls the listening address, port, memory limit, and other runtime options; make changes only when you understand their effect, then restart the service with sudo systemctl restart memcached.

For a cache used only by applications on the same host, bind Memcached to the loopback interface, such as 127.0.0.1, where the package’s configuration allows it. Do not expose the service to the public internet. Memcached is not designed to be safely left open to untrusted networks, and a firewall rule alone is not a substitute for a correct listening-address configuration. If remote application servers need access, restrict traffic to trusted hosts and private networks, and use network controls appropriate to the environment.

Do not assume that a distribution’s default memory allocation or connection settings fit every workload. Check available memory and the application’s needs before adjusting limits; reserving too much memory can affect other services. Restarting can clear cached entries, so plan changes with the understanding that the application may temporarily have to refill its cache.

Verify installation and connect an application

First check the service with systemctl status memcached. To see whether a local TCP listener exists, use an available tool such as ss -ltn and look for the configured port, commonly 11211. The output should show the intended address, not an unexpectedly public interface.

A command-line client such as nc may be used for a simple local protocol check if installed. For example, connect to 127.0.0.1 on the configured port, send version followed by a newline, and expect a version response. Close the connection afterward. This confirms basic reachability; it does not verify that an application’s client library or cache configuration is correct.

In your application, set the Memcached server address and port using the configuration mechanism documented by that application. A local service is typically addressed as 127.0.0.1:11211 when it listens on loopback and uses the default port. Install the application’s own Memcached client library separately if required. Test with a noncritical cache entry and confirm that the application can still function when a cached entry is missing.

Common installation problems

  • Package not found: Refresh package indexes, verify the distribution and release, and check that the appropriate repositories are enabled. Do not substitute a package intended for another Linux distribution.
  • Service fails to start: Inspect sudo journalctl -u memcached for startup errors. A configuration typo, invalid option, or unavailable port can prevent startup.
  • Connection refused: Confirm the service is active, the application is using the correct host and port, and the service is listening on that address.
  • Remote connection times out: Check the configured bind address and network firewall rules. Do not solve the problem by making the cache reachable from every network.
  • Application does not use the cache: Installing the daemon is only one part of setup. Verify that the application has a compatible client and is configured to use Memcached rather than another cache backend.

Frequently Asked Questions

How do I check whether Memcached is installed?
Use the distribution’s package query tools, or run systemctl status memcached. A missing systemd unit can mean the package is not installed, though service naming differs across distributions.

Does Memcached start automatically after installation?
It may start during installation, depending on the distribution and package settings. Check with systemctl status memcached; use sudo systemctl enable --now memcached to enable and start it through systemd.

What port does Memcached use?
Its commonly used default TCP port is 11211, but the configured port may differ. Check the service configuration and listening sockets rather than relying on the default.

Is Memcached a database?
No. It stores temporary cached data in memory and should not be treated as durable storage. Applications need a source of truth, such as a database, from which missing cache entries can be recreated.

Can I access Memcached from another server?
Yes, if it is deliberately configured to listen on a reachable private interface and network access is restricted to trusted systems. Do not expose an unrestricted Memcached listener to the public internet.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →