Install Redis on Ubuntu 22.04

In this guide, we will go through how to install Redis on Ubuntu 22.04. Redis is a distributed, in-memory key-value database, cache, and message broker with optional durability that is used as an in-memory data structure store. Various abstract data structures, including strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indices, are supported by Redis.

How to install Redis on Ubuntu 22.04

  • Update your system packages by running the command below.
sudo apt update
  • Then install Redis on Ubuntu using the command below.
sudo apt install redis-server

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libatomic1 libjemalloc2 liblua5.1-0 liblzf1 lua-bitop lua-cjson
  redis-tools
Suggested packages:
  ruby-redis
The following NEW packages will be installed:
  libatomic1 libjemalloc2 liblua5.1-0 liblzf1 lua-bitop lua-cjson
  redis-server redis-tools
0 upgraded, 8 newly installed, 0 to remove and 3 not upgraded.
Need to get 1,283 kB of archives.
After this operation, 5,771 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 libatomic1 amd64 12-20220319-1ubuntu1 [10.4 kB]
Get:2 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 libjemalloc2 amd64 5.2.1-4ubuntu1 [240 kB]
Get:3 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 liblua5.1-0 amd64 5.1.5-8.1build4 [99.9 kB]
Get:4 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 liblzf1 amd64 3.6-3 [7,444 B]
Get:5 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 lua-bitop amd64 1.0.2-5 [6,680 B]
Get:6 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 lua-cjson amd64 2.1.0+dfsg-2.1 [17.4 kB]
Get:7 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 redis-tools amd64 5:6.0.16-1ubuntu1 [856 kB]
Get:8 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 redis-server amd64 5:6.0.16-1ubuntu1 [45.9 kB]
Fetched 1,283 kB in 2s (700 kB/s)       
Selecting previously unselected package libatomic1:amd64.   
  • After the installation, Redis should be up and running. Check the status using the command below.
systemctl status redis-server

Sample output

● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-09-06 15:48:57 EAT; 1min 50s ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
   Main PID: 7950 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 4584)
     Memory: 2.9M
        CPU: 353ms
     CGroup: /system.slice/redis-server.service
             └─7950 "/usr/bin/redis-server 127.0.0.1:6379" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Sep 06 15:48:57 itnixpro systemd[1]: Starting Advanced key-value store...
Sep 06 15:48:57 itnixpro systemd[1]: Started Advanced key-value store.
  • Check the Redis version installed.
redis-server -v
  • Next, using a ping test, verify the Redis server is operational using the following command.
redis-cli
ping

Sample output

127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit

Set Redis password on Ubuntu 22.04

  • Edit Redis configuration file.
sudo nano /etc/redis/redis.conf
  • Then search for requirepass foobared and uncomment it by removing the # symbol. Replace foobared with your preferred password.
# IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
# layer on top of the new ACL system. The option effect will be just setting
# the password for the default user. Clients will still authenticate using
# AUTH  as usually, or more explicitly with AUTH default 
# if they follow the new protocol: both will work.
#

requirepass YourStrongPassword

# Command renaming (DEPRECATED).
#
# ------------------------------------------------------------------------
# WARNING: avoid using this option if possible. Instead use ACLs to remove
# commands from the default user, and put them only in some admin user you
# create for administrative purposes.
# ------------------------------------------------------------------------
  • After setting the Redis password, restart it to apply changes.
sudo systemctl restart redis
  • When you try again to do the ping test you will be required to authenticate with your password.
redis-cli

Sample output

127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth YourStrongPassword
OK
127.0.0.1:6379> exit
  • You have made it to the end of our tutorial. We have gone through how to install Redis on Ubuntu 22.04.

Read more on Redis Documentation

Other Tutorials

Install Rust on FreeBSD 13

Install Apache Tomcat on Fedora 36

Install Apache Tomcat on Ubuntu 22.04

System administrator | Software Developer | DevOps

Leave a Comment