Skip to content
Follow
Ubuntu Linux

How to Install Memcached on Ubuntu Linux

Richard
Written by
Richard
Oct 15, 2021 Updated Jul 10, 2026 4 min read
How to Enable or Disable Microsoft Defender Cloud Protection
How to Enable or Disable Microsoft Defender Cloud Protection

You install Memcached on Ubuntu Linux to significantly boost the performance of dynamic web applications by caching frequently accessed data directly in RAM.

Memcached, an open-source, in-memory key-value store, reduces database load. Memcached saves common query and object retrieval results. This action speeds up website response times.

Memcached integration slashes loading times for WordPress or Drupal by caching database lookups and API calls. This caching technology handles high traffic. Memcached version 1.6.13 boasts performance improvements, ensuring a snappy user experience.

Installing Memcached on Ubuntu Linux provides straightforward server-side caching for users. This process makes Memcached accessible for those new to server-side caching.

⚡ Quick Answer

Install Memcached by running sudo apt update and then sudo apt install memcached libmemcached-tools in your terminal. Verify it’s running with sudo systemctl status memcached.

How to install Memcached on Ubuntu Linux

Installing Memcached on Ubuntu Linux is simple using the terminal. You just need to run two commands to update your software list and then install Memcached itself. This makes sure you get the latest version and have the necessary tools to manage it, as Ubuntu keeps it ready to go.

🐧Bash / Shell
sudo apt update
sudo apt install memcached libmemcached-tools

Memcached tools provide several command line tools for managing the Memcached server. You’ll mostly want to install it with the Memcached server.

After running the commands above, the Memcached server should be installed and ready to use. To check its status, run the commands below:

🐧Bash / Shell
sudo systemctl status memcached

You should see similar lines below:

💻Code
● memcached.service - memcached daemon
   Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-06-06 10:36:25 CDT; 27s ago
     Docs: man:memcached(1)
 Main PID: 19852 (memcached)
    Tasks: 10 (limit: 4682)
   CGroup: /system.slice/memcached.service
           └─19852 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -P /var/run/memcached/memcached.pid

Jun 06 10:36:25 ubuntu1804 systemd[1]: Started memcached daemon.

The server should be running and should respond to requests. The commands below can be used to stop, start and enable Memcached.

🐧Bash / Shell
sudo systemctl stop memcached.service
sudo systemctl start memcached.service
sudo systemctl enable memcached.service

How to configure Memcached on Ubuntu Linux

Configuring Memcached on Ubuntu Linux involves editing its main settings file found at /etc/memcached.conf. While the default settings work well for most people, you can adjust them here if you have special needs. This file is where you fine-tune how Memcached runs on your system.

The default settings in the file should be 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.

⚠️Warning
Memcached listens on the server's local IP address, 127.0.0.1. To make Memcached listen on a different IP address, edit the configuration file. Change the relevant lines to match the new IP address you specify.
🐧Bash / Shell
sudo nano /etc/memcached.conf

Then replace the local server IP with the one you want to use. You can also change its default port number as well.

💻Code
# 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 192.168.2.1

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

How to block remote access to Memcached

Blocking remote access to Memcached on Ubuntu is important for security and is done by editing its configuration file. This stops unwanted connections from outside your network. You can tell Memcached which specific IP addresses are allowed to connect, keeping your data safe by denying others.

You can define the remote client IP in the configuration file above. IPs that are not in the file above are automatically denied access remotely.

⚠️Warning
The Ubuntu firewall blocks all remote clients from accessing Memcached on port 11211. Only explicitly allowed clients can connect to the Memcached service, preventing unauthorized access and improving security.
🐧Bash / Shell
sudo ufw allow from 192.168.2.1 to any port 11211

Th

To use Memcached as a caching database for your PHP application, such as WordPress, Drupal, Joomla, or Magento, you need to install the php-memcached extension.

Run the commands below to install the PHP Memcached PHP extension.

🐧Bash / Shell
sudo apt install php-memcached

To use Memcached with Python, install the extension below.

💻Code
pip install pymemcache

pip install python-memcached

That should do it!

Conclusion:

  • Memcached is a powerful tool for improving the performance of web applications by caching data in memory.
  • Installing and configuring Memcached on Ubuntu Linux is a straightforward process, suitable for both students and new users.
  • Proper configuration and security measures are essential to prevent unauthorized access and potential misuse.
  • Integrating Memcached with PHP applications enhances efficiency, making it an excellent choice for frameworks like WordPress and Drupal.
  • Explore additional extensions for languages like Python to take full advantage of Memcached’s capabilities.
  • Overall, implementing Memcached can significantly enhance your application’s speed and responsiveness.

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.

📚 Related Tutorials

How to Install Ubuntu Linux
Ubuntu Linux How to Install Ubuntu Linux
How to Setup WordPress with Nginx and Cloudflare on Ubuntu
CMS How to Setup WordPress with Nginx and Cloudflare on Ubuntu
How to Install Drupal with Nginx and Cloudflare on Ubuntu
CMS How to Install Drupal with Nginx and Cloudflare on Ubuntu
How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04

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

Leave a Comment

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