How To Install Redis on Ubuntu 22.04|20.04|18.04

Posted on 83 views

In this tutorial, I’ll walk you through the steps to install Redis Server on Ubuntu 22.04|20.04|18.04 Linux system. Redis is an Open Source in-memory data structure store. Redis can be used as a database server, as a message broker or for caching data in memory for faster retrieval.

Redis supported data structures are:

  • Hashes
  • sets with range queries
  • Strings
  • sorted lists
  • Hyperloglogs
  • Bitmaps
  • Geospatial indexes e.t.c

For CentOS 8 / CentOS 7 / Fedora use:

Install Redis on Ubuntu 22.04|20.04|18.04

In this section, we will look at how to install the latest release of Redis on Ubuntu. You can check the version of Redis Server available on your Ubuntu 22.04|20.04|18.04 using the following command.

$ sudo apt update
$ sudo apt policy redis-server
  Installed: (none)
  Candidate: 5:5.0.7-2 500
  Version table:
     5:5.0.7-2 500
        500 focal/universe amd64 Packages

Step 1: Update your server Package list

Ensure your system is updated before installing Redis

sudo apt update

Step 2: Install Redis on Ubuntu 22.04|20.04|18.04

Redis Server package is available on the  Ubuntu upstream repository. After updating your system, install Redis by running the following commands in your terminal.

sudo apt -y install redis-server

If you would like to have a more recent version of Redis Server, you may opt to use PPA repository maintained by Redis Development.

sudo add-apt-repository ppa:redislabs/redis
sudo apt-get update
sudo apt-get install redis

If you don’t have add-apt-repository command on your system, check our previous guide:

  • How to Install add-apt-repository on Debian / Ubuntu

Confirm Redis Server version:

$ redis-server -v
Redis server v=6.2.6 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=9c9e426e2f96cc51

Step 3: Start Redis Service on Ubuntu 22.04|20.04|18.04

By default, Redis service should be started after installation. But you can start and enable the service to start on boot manually using the command:

sudo systemctl enable --now redis-server

Step 4: Enable network Listen for Redis Service

For network clients to connect to your Redis server, it needs the service to listen on a network IP Address.

Open the file /etc/redis/redis.conf with your favorite text editor

sudo vim /etc/redis/redis.conf

Then change line  bind to below:


Restart redis service after making the change:

sudo systemctl restart redis-server

Step 5: Configure Redis Authentication – (Optional but recommended)

Configure Redis Authentication for clients to require AUTH  before processing any other commands.



requirepass oobaiY8BA

Step 6: Set Persistent Store for Recovery (Optional)

Set persistence mode by changing the appendonlyvalue to yes

appendonly yes
appendfilename "appendonly.aof"

Restart redis service after making the changes

sudo systemctl restart redis-server

Check redis service status:

$ systemctl status redis-server
* redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2018-12-23 03:42:41 PST; 1s ago
  Process: 10444 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
  Process: 10447 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
 Main PID: 10469 (redis-server)
    Tasks: 4 (limit: 2319)
   CGroup: /system.slice/redis-server.service
           `-10469 /usr/bin/redis-server

Dec 23 03:42:40 ubuntu-01 systemd[1]: Starting Advanced key-value store...
Dec 23 03:42:41 ubuntu-01 systemd[1]: Started Advanced key-value store.

You can view the port and IP used by Redis service using the sscommand:

$ ss -tunelp | grep 6379
tcp LISTEN 0 128* uid:112 ino:52652 sk:40 <->

If you have an active firewall service, allow port 6379

sudo ufw allow 6379/tcp

Step 7: Test connection to Redis Server

Confirm that you can connect to redis locally:

$ redis-cli>

Test authenticate:> AUTH 

You should receive OK in the output. If you input a wrong password, Authentication should fail:> AUTH WrongPassword
(error) ERR invalid password

Check redis information.>  INFO

This will output a long list of data. You can limit the output by passing Section as an argument. E.g.> INFO Server
# Server
os:Linux 4.15.0-38-generic x86_64

Step 8: Perform Redis Benchmarking

Run the benchmark with 15 parallel connections, for a total of 10k requests, against local redis to test its performance.

$ redis-benchmark -h -p 6379 -n 10000 -c 15

# Sample output
====== LRANGE_500 (first 450 elements) ======
  10000 requests completed in 0.62 seconds
  15 parallel clients
  3 bytes payload
  keep alive: 1

99.66% <= 1 milliseconds
100.00% <= 1 milliseconds
16129.03 requests per second

====== LRANGE_600 (first 600 elements) ======
  10000 requests completed in 0.81 seconds
  15 parallel clients
  3 bytes payload
  keep alive: 1

99.66% <= 1 milliseconds
99.93% <= 2 milliseconds
99.97% <= 3 milliseconds
100.00% <= 3 milliseconds
12345.68 requests per second

====== MSET (10 keys) ======
  10000 requests completed in 0.09 seconds
  15 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
111111.11 requests per second

For more options and examples, use:

$ redis-benchmark --help

You have successfully installed Redis on Ubuntu 22.04|20.04|18.04 Server or Workstation.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.