How to Install Redis on Ubuntu 20.04/22.04

What is really the hype behind Redis? Redis has created a reputation for itself as the go-to data store. It is attributed as a key-value, in-memory, and open-source data store. These attributes make Redis an ideal message broker, cache, and database candidate/application.

Also, Redis’ resume illustrates its support for numerous data structures like Sets, Hashes, Lists, and Strings. Through features like automatic partitioning and Redis Sentinel, multiple Redis nodes and Redis Cluster provide high Redis availability.

Prerequisite

Be a sudoer/root user on the Ubuntu operating system you are using.

Installing Redis on Ubuntu

Make sure your Ubuntu operating system is up-to-date as it helps with the performance optimization of installed and yet-to-be-installed application packages.

$ sudo apt update && sudo apt upgrade -y 

Next, run the following command to install Redis on your Ubuntu system.

$ sudo apt install redis-server -y
Install Redis in Ubuntu
Install Redis in Ubuntu

Once the installation process completes, confirm Redis installed version on your system.

$ redis-server --version
Check Redis Version in Ubuntu
Check Redis Version in Ubuntu

Next, enable and check Redis’s status to be sure it is up and running.

$ sudo systemctl enable redis-server 
$ sudo systemctl status redis-server 
Check Redis Status in Ubuntu
Check Redis Status in Ubuntu

Configuring Redis on Ubuntu

Now that we have installed and confirmed that Redis is up and running, it is time to implement some important configurations. The default installation of Redis does not permit remote connections. Redis’ default configuration only permits localhost (127.0.0.1) connections on the machine hosting it.

You do not need to enable remote access/connection on your Redis configuration if you have a single server setup. However, if for some reason a separate/remote server setup is running Redis, you will need to configure it to handle remote connections.

The following command should open Redis’ main configuration file on your Ubuntu system:

$ sudo nano /etc/redis/redis.conf 

Trace the following sections on the file:

Redis Configuration File
Redis Configuration File

This section demonstrates how to bind Redis to all or specific remote machines’ IP addresses. For instance, if we want any remote user to be able to access this Redis server, we will edit out or comment on the line bind 127.0.0.1 ::1 and replace it with bind 0.0.0.0 ::1.

Enable Redis Remote Connection
Enable Redis Remote Connection

For the implemented configuration changes to be effective, restart the Redis server.

$ sudo systemctl restart redis-server 

Next, verify that all Redis is listening to its associated interfaces.

$ ss -an  | grep 6379 
Check Redis Listening State
Check Redis Listening State

Since Redis communicates via port 6379, your firewall (if active) should be configured to allow traffic through this port.

$ sudo ufw allow 6379/tcp
$ sudo ufw reload 
$ sudo ufw status 

Testing Redis Remote Connection

On the remote machine that wishes to connect to the Redis server, install redis-tools to facilitate this client-to-server communication.

$ sudo apt install redis-tools -y 

Next, we will now use the redis-cli utility to ping the Redis server via IP address.

$ redis-cli -h 192.168.100.23 ping
Test Redis Remote Connection
Test Redis Remote Connection

The output PONG confirms that the two remote computers can communicate with one another.

This article has walked us through the installation, configuration, and testing of the Redis server on Ubuntu. For a more thorough Redis configuration guide, reference the file /etc/redis/redis.conf.

1 thought on “How to Install Redis on Ubuntu 20.04/22.04”

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.