How To Install Memcached on Linux Mint 22

Looking to supercharge your web application’s performance? Installing Memcached on Linux Mint 22 might be exactly what you need. This powerful distributed memory caching system can dramatically reduce database load and slash page load times by storing frequently accessed data in RAM. Whether you’re running a WordPress site, a custom web application, or managing multiple database-driven services, Memcached acts as a high-speed intermediary between your application and database.
In this comprehensive guide, you’ll learn how to install Memcached on Linux Mint 22 from scratch. We’ll walk through every step, from basic installation to advanced security configurations. By the end, you’ll have a fully functional, secured caching system ready to boost your application’s speed. No prior experience with caching systems required—just follow along.
What is Memcached?
Memcached is a free, open-source, high-performance distributed memory caching system. Think of it as a giant, lightning-fast temporary storage area sitting in your server’s RAM. Instead of your application repeatedly querying the database for the same information, Memcached stores that data in memory for instant retrieval.
The beauty of Memcached lies in its simplicity. It operates as an in-memory key-value store, meaning you store data using a unique key and retrieve it later using that same key. When your application needs information, it checks Memcached first. If the data exists there (called a “cache hit”), you get sub-millisecond response times. If not (a “cache miss”), the application fetches from the database and stores a copy in Memcached for next time.
Why Use Memcached?
The benefits are substantial. Memcached reduces database load significantly, which means your database can handle more concurrent users without breaking a sweat. Common use cases include caching web pages, storing session data, speeding up API responses, and reducing repetitive database queries. Major platforms like Facebook, Twitter, and YouTube have relied on Memcached to serve millions of users simultaneously.
It’s also incredibly cost-effective. By reducing the strain on your database servers, you might delay expensive hardware upgrades. The system scales horizontally, meaning you can add more Memcached servers as your needs grow.
Prerequisites
Before diving into the installation process, ensure you have the following ready:
- A Linux Mint 22 system with a fresh installation or properly maintained setup
- Sudo privileges or root access to install packages and modify system files
- An active internet connection for downloading packages from repositories
- At least 512MB of available RAM (more is better for production environments)
- Basic comfort with the terminal and command-line interface
- Optional: knowledge of firewall configuration if you plan remote access
Linux Mint 22 is based on Ubuntu 24.04 LTS, which means most Ubuntu-compatible packages work seamlessly. This compatibility makes Memcached installation straightforward since it’s available in the default repositories.
Step 1: Update System Packages
First things first—update your package index. This ensures you’re installing the latest available version of Memcached and all dependencies. Open your terminal using Ctrl+Alt+T or find it in your application menu.
Run this command:
sudo apt update
This command refreshes your system’s package database. You’ll see a list of repositories being queried and packages being indexed. The process typically takes 30 seconds to a minute, depending on your internet speed and the number of repositories configured.
While optional, it’s good practice to upgrade existing packages:
sudo apt upgrade -y
The -y flag automatically confirms the upgrade without prompting. Your system will download and install any available updates.
Step 2: Install Memcached and Supporting Tools
Now for the main event—installing Memcached itself. Linux Mint 22’s repositories include Memcached, so no third-party sources are necessary. This makes installation secure and straightforward.
Installing Memcached
Execute this command:
sudo apt install memcached -y
The installation pulls in Memcached along with required dependencies. You’ll see output showing package downloads, unpacking, and configuration. The entire process usually completes in under a minute on modern systems.
Installing Management Tools
Next, install the libmemcached-tools package. This collection includes utilities for testing and managing your Memcached instance:
sudo apt install libmemcached-tools -y
These tools include memcstat (for viewing statistics), memcping (for testing connectivity), and other helpful utilities. They’re invaluable for troubleshooting and monitoring cache performance.
The installation automatically configures Memcached to start as a system service. It even enables auto-start on boot, so your caching layer survives server reboots.
Step 3: Verify Memcached Installation
Let’s confirm everything installed correctly. Check the service status with:
sudo systemctl status memcached
You should see output indicating the service is “active (running)”. Look for a green dot or the word “active” in green text. The output also shows memory usage, process ID, and recent log entries.
To check which version you installed, run:
memcached -h | head -n 1
This displays the Memcached version number. As of early 2026, version 1.6.x is common in Ubuntu-based distributions.
If the status shows “inactive” or “failed,” the service isn’t running properly. Jump to the troubleshooting section later in this article for solutions.
Step 4: Configure Memcached
Out of the box, Memcached works with sensible defaults. However, customizing the configuration optimizes performance for your specific needs.
Accessing the Configuration File
The main configuration file lives at /etc/memcached.conf. Open it with your preferred text editor. We’ll use nano:
sudo nano /etc/memcached.conf
Nano is beginner-friendly. Use arrow keys to navigate, type to edit, and press Ctrl+X, then Y, then Enter to save and exit.
Understanding Key Configuration Parameters
Let’s explore the most important settings:
Memory Allocation (-m): This defines how much RAM Memcached can use. The default is typically 64MB. For production environments handling significant traffic, increase this value. For example:
-m 256
This allocates 256MB. Adjust based on your server’s available memory and workload.
Port Configuration (-p): Memcached listens on port 11211 by default. Unless you have a specific reason, leave this unchanged:
-p 11211
User Configuration (-u): For security, Memcached runs as a non-privileged user called “memcache”:
-u memcache
Never run Memcached as root. This limitation contains potential security breaches.
Listen Address (-l): By default, Memcached only accepts connections from localhost (127.0.0.1):
-l 127.0.0.1
This is perfect if your application runs on the same server. For remote access, you have options. You can bind to all interfaces with 0.0.0.0, though this poses security risks without proper authentication. Better practice: specify your server’s private IP address:
-l 192.168.1.100
Replace 192.168.1.100 with your actual server IP.
Maximum Connections: Control how many simultaneous connections Memcached accepts:
-c 1024
The default 1024 works for most scenarios. High-traffic sites might need more.
After making changes, save the file. Configuration changes don’t take effect until you restart the service.
Step 5: Start and Enable Memcached Service
With configuration complete, manage the Memcached service using systemctl commands.
To start Memcached immediately:
sudo systemctl start memcached
No output means success. Linux follows the “no news is good news” philosophy for successful commands.
Enable automatic startup at boot time:
sudo systemctl enable memcached
You’ll see a message confirming the symbolic link creation.
After configuration changes, restart the service:
sudo systemctl restart memcached
This stops and starts Memcached with the new settings.
Verify the service is running and listening on the correct port:
sudo ss -tulpn | grep memcached
This shows network sockets. You should see Memcached listening on 127.0.0.1:11211 (or your configured IP and port).
Step 6: Test Memcached Connection
Testing confirms Memcached is functioning correctly and ready to cache data.
Using memcstat Tool
The memcstat utility provides instant statistics. Run:
memcstat --servers="127.0.0.1"
If you changed the listen address, adjust accordingly. Successful output displays server information like version, uptime, current connections, and memory usage. A working Memcached instance returns statistics without errors.
For more detailed statistics:
echo "stats" | nc localhost 11211
This uses netcat to send the stats command. You’ll see dozens of metrics including total items stored, cache hits and misses, bytes used, and more.
Testing with Telnet
Telnet lets you interact directly with Memcached using its text protocol. First, install telnet if it’s not present:
sudo apt install telnet -y
Connect to Memcached:
telnet localhost 11211
You’ll see a connection confirmation. Now you can manually cache and retrieve data.
Store a test value:
set testkey 0 120 5
hello
Breaking this down: set is the command, testkey is your unique identifier, 0 is flags (usually 0), 120 is expiration in seconds, and 5 is the byte length of your data. After pressing Enter, type your value (hello) and press Enter again. Memcached responds with STORED.
Retrieve the value:
get testkey
You’ll see your stored data returned. This confirms Memcached is caching and retrieving successfully.
Check statistics:
stats
This outputs all available metrics.
Exit telnet:
quit
Step 7: Configure Firewall for Remote Access (Optional)
If your application servers exist separately from your Memcached server, configure firewall rules for remote connectivity.
Linux Mint typically uses UFW (Uncomplicated Firewall). Check if it’s active:
sudo ufw status
To allow Memcached connections through the firewall:
sudo ufw allow 11211/tcp
For enhanced security, restrict access to specific IP addresses only. If your application server is at 192.168.1.50:
sudo ufw allow from 192.168.1.50 to any port 11211
This permits only that specific IP to connect.
Reload the firewall to apply changes:
sudo ufw reload
Verify the rule exists:
sudo ufw status numbered
Important security note: Never expose Memcached to the public internet without authentication. Default Memcached installations lack authentication, making them vulnerable to unauthorized access and potential data theft.
Step 8: Secure Memcached with SASL Authentication
Authentication adds a critical security layer, especially when allowing remote connections.
Why SASL Matters
Default Memcached accepts any connection without verifying identity. This means anyone reaching your Memcached port can read cached data or inject malicious content. SASL (Simple Authentication and Security Layer) requires username and password authentication before granting access.
Installing SASL Support
Install the required SASL packages:
sudo apt install sasl2-bin -y
Create a directory for SASL configuration:
sudo mkdir -p /etc/sasl2
Create the Memcached SASL configuration file:
sudo nano /etc/sasl2/memcached.conf
Add these lines:
mech_list: plain
log_level: 5
sasldb_path: /etc/sasl2/memcached-sasldb2
Save and exit. This configuration tells SASL to use plain text passwords (they’re encrypted over the connection) and specifies where to store user credentials.
Creating Authenticated Users
Create a Memcached user with this command:
sudo saslpasswd2 -a memcached -c -f /etc/sasl2/memcached-sasldb2 username
Replace username with your desired username. You’ll be prompted to enter and confirm a password. Choose something strong.
Set proper ownership:
sudo chown memcache:memcache /etc/sasl2/memcached-sasldb2
This ensures Memcached can read the authentication database.
Now enable SASL in Memcached’s configuration. Edit /etc/memcached.conf:
sudo nano /etc/memcached.conf
Add this line:
-S
The -S flag enables SASL authentication.
Restart Memcached:
sudo systemctl restart memcached
Test authenticated access. With authentication enabled, unauthenticated connections will fail, confirming your security is active.
Troubleshooting Common Issues
Even straightforward installations occasionally hit snags. Here’s how to resolve common problems.
Service Won’t Start
If Memcached fails to start, check the system logs:
sudo journalctl -u memcached -n 50
This displays the last 50 log entries. Look for error messages indicating the problem.
Common causes include syntax errors in /etc/memcached.conf. Verify your configuration file doesn’t have typos. Another possibility: port 11211 is already in use by another process. Check with:
sudo lsof -i :11211
If another service occupies the port, either stop that service or configure Memcached to use a different port.
Connection Refused Errors
When clients can’t connect, verify the service is actually running:
sudo systemctl status memcached
Check your firewall rules with sudo ufw status. Ensure you’ve allowed the appropriate connections.
Confirm the listen address in /etc/memcached.conf matches where you’re trying to connect. If Memcached listens only on 127.0.0.1, remote connections won’t work regardless of firewall settings.
Memory Issues
If Memcached seems slow or evicts items too frequently, you might need more allocated memory. Edit /etc/memcached.conf and increase the -m value. Monitor actual memory usage with:
memcstat --servers="127.0.0.1" | grep limit_maxbytes
Memcached uses an LRU (Least Recently Used) eviction policy. When memory fills up, it automatically removes the least recently accessed items. Frequent evictions suggest insufficient memory allocation for your workload.
Permission Errors
SASL-related permission errors usually stem from incorrect ownership of the authentication database. Double-check:
ls -l /etc/sasl2/memcached-sasldb2
The file should be owned by the memcache user. If not, fix it:
sudo chown memcache:memcache /etc/sasl2/memcached-sasldb2
Performance Issues
Slow Memcached performance has several potential causes. Check system resources with htop or top. If your server is memory-constrained, Memcached can’t perform optimally.
Review connection limits in your configuration. Insufficient maximum connections cause client connection failures under load.
Monitor your cache hit ratio. This metric reveals how often cached data is successfully retrieved versus how often cache misses occur. A low hit ratio suggests your caching strategy needs refinement at the application level.
Congratulations! You have successfully installed Memcached. Thanks for using this tutorial for installing the latest version of Memcached on the Linux Mint 22 system. For additional help or useful information, we recommend you check the official Memcached website.