How to Install Memcached on Ubuntu 22.04

Install Memcached on Ubuntu 22.04

In this article, we will have explained the necessary steps to install Memcached on Ubuntu 22.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Memcached is a memory object caching system specifically designed to enhance the speed of dynamic web applications by reducing the load of the database server. In this way, they reduce the number of direct requests to your databases. Because Memcached relies on RAM, it can be expensive to scale up if you have a large website with a lot of traffic.

Prerequisite:

  • Operating System with Ubuntu 22.04
  • Server IPv4 Address with Superuser Privileges (Root Access)
  • Gnome Terminal for Linux Desktop
  • PuTTy SSH client for Windows or macOS
  • Powershell for Windows 10/11
  • Familiar with APT Commands

Install Memcached on Ubuntu 22.04 LTS

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade
sudo apt install software-properties-common apt-transport-https wget

Step 2. Install Memcached on Ubuntu.

Memcached installation is quite easy and straightforward since the Memcached package is accessible in the repositories of the majority of Linux distributions. To install Memcached, enter the following command:

sudo apt install memcached libmemcached-tools

Now you can verify that Memcached was installed:

memcached --version

To start Memcached, run the following systemctl command:

sudo systemctl enabled memcached --now
sudo systemctl start memcached

In addition, you can also enable Memcached for PHP applications. It can easily be installed using the APT package manager. Here is the command:

sudo apt install php-memcached

Step 3. Configure Memcached on Ubuntu.

For configuration, we will open its config file using your favorite text editor:

sudo nano /etc/memcached.conf

Leave as the default unless you have internal IP on a local network or external IP from outside; you must modify the default IP address from 127.0.0.1 to the new IP address:

-l 127.0.0.1

Next, recommended disabling UDP:

-U 0

Now change the default 64MB memory allocation is recommended as this isn’t much for larger websites, and you will not see much benefit using Memcached:

-m 2000

Save the file, then exit and restart your Memcached instance:

sudo systemctl restart memcached

Step 4. Configure Firewall.

Don’t forget to allow TCP port 11211 in your server firewall. If you are using Ubuntu’s UFW firewall then you have to open the port in that for remote connection; use the given command:

sudo ufw allow 11211/tcp

Step 5. Memcached Command line.

To use the command line for configuring Memcached, use its command line. For that simply type:

memcached –option

To know what Options are available to use, see its help section:

memcached -h

That’s all you need to do to install Memcached on Ubuntu 22.04 LTS Jammy Jellyfish. I hope you find this quick tip helpful. For further reading on the installation of the Memcached distributed memory object caching system, please refer to their official knowledge base. I hope this article was helpful to you. If you find it useful, don’t forget to share it with your friend and family. Also, if you have any questions, please feel free to ask in the comments section. We are always there to assist you.