How to Install and Configure Redis on Ubuntu 20.04

In this article, we’ll see how to install and configure Redis on Ubuntu 20.04. Redis is an open-source in-memory data structure store, used as a database, cache, and message broker.

Steps to Install Redis on Ubuntu 20.04

Step 1: Add PPA chris-lea/redis-server repository

sudo apt-get update

sudo add-apt-repository ppa:chris-lea/redis-server

Sample Output:

ubuntu@Redis-server:~$ sudo add-apt-repository ppa:chris-lea/redis-server
Repository: 'deb http://ppa.launchpad.net/chris-lea/redis-server/ubuntu/ groovy main'
Description:
Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
More info: https://launchpad.net/~chris-lea/+archive/ubuntu/redis-server
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
Adding deb entry to /etc/apt/sources.list.d/chris-lea-ubuntu-redis-server-groovy.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/chris-lea-ubuntu-redis-server-groovy.list
Adding key to /etc/apt/trusted.gpg.d/chris-lea-ubuntu-redis-server.gpg with fingerprint 136221EE520DDFAF0A905689B9316A7BC7917B12
Ign:1 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 InRelease 
Ign:2 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu groovy InRelease 
Get:3 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 Release [5,372 B]
Hit:4 http://us.archive.ubuntu.com/ubuntu groovy InRelease 
Get:5 https://repos.influxdata.com/ubuntu bionic InRelease [4,737 B] 
Hit:6 https://artifacts.elastic.co/packages/oss-6.x/apt stable InRelease 
Hit:7 http://repo.zabbix.com/zabbix/5.2/ubuntu focal InRelease 
Get:8 http://security.ubuntu.com/ubuntu groovy-security InRelease [110 kB] 
Get:9 http://us.archive.ubuntu.com/ubuntu groovy-updates InRelease [115 kB] 
Get:10 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 Release.gpg [801 B]
Err:11 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu groovy Release 
404 Not Found [IP: 91.189.95.85 80]
Get:12 https://repos.influxdata.com/ubuntu bionic/stable amd64 Packages [1,066 B]
Get:13 https://repos.influxdata.com/ubuntu bionic/stable i386 Packages [918 B]
Get:14 http://security.ubuntu.com/ubuntu groovy-security/main i386 Packages [103 kB]
Get:15 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4/multiverse amd64 Packages [10.8 kB]
Get:16 http://us.archive.ubuntu.com/ubuntu groovy-backports InRelease [101 kB]
Get:18 http://security.ubuntu.com/ubuntu groovy-security/main amd64 Packages [285 kB]
Get:19 http://us.archive.ubuntu.com/ubuntu groovy-updates/main i386 Packages [194 kB]
Get:20 http://security.ubuntu.com/ubuntu groovy-security/main Translation-en [68.2 kB]
Hit:17 https://packages.graylog2.org/repo/debian stable InRelease 
Get:21 http://security.ubuntu.com/ubuntu groovy-security/main amd64 DEP-11 Metadata [18.8 kB]
Get:22 http://us.archive.ubuntu.com/ubuntu groovy-updates/main amd64 Packages [443 kB]
Get:23 http://security.ubuntu.com/ubuntu groovy-security/main DEP-11 48x48 Icons [8,330 B]
Get:24 http://security.ubuntu.com/ubuntu groovy-security/main DEP-11 64x64 Icons [12.1 kB]
Get:25 http://security.ubuntu.com/ubuntu groovy-security/main amd64 c-n-f Metadata [3,880 B]
Get:26 http://security.ubuntu.com/ubuntu groovy-security/universe amd64 Packages [67.4 kB]
Get:27 http://security.ubuntu.com/ubuntu groovy-security/universe i386 Packages [50.7 kB]
Get:28 http://security.ubuntu.com/ubuntu groovy-security/universe Translation-en [31.4 kB]
Get:29 http://security.ubuntu.com/ubuntu groovy-security/universe amd64 DEP-11 Metadata [4,612 B]
Get:30 http://security.ubuntu.com/ubuntu groovy-security/universe amd64 c-n-f Metadata [3,064 B]
Get:31 http://us.archive.ubuntu.com/ubuntu groovy-updates/main Translation-en [111 kB]
Get:32 http://us.archive.ubuntu.com/ubuntu groovy-updates/main amd64 DEP-11 Metadata [55.5 kB]
Get:33 http://us.archive.ubuntu.com/ubuntu groovy-updates/main DEP-11 48x48 Icons [31.4 kB]
Get:34 http://us.archive.ubuntu.com/ubuntu groovy-updates/main DEP-11 64x64 Icons [52.1 kB]
Get:35 http://us.archive.ubuntu.com/ubuntu groovy-updates/main amd64 c-n-f Metadata [7,492 B]
Get:36 http://us.archive.ubuntu.com/ubuntu groovy-updates/restricted i386 Packages [15.9 kB]
Get:37 http://us.archive.ubuntu.com/ubuntu groovy-updates/restricted amd64 Packages [162 kB]
Get:38 http://us.archive.ubuntu.com/ubuntu groovy-updates/universe i386 Packages [88.1 kB]
Get:39 http://us.archive.ubuntu.com/ubuntu groovy-updates/universe amd64 Packages [164 kB]
Get:40 http://us.archive.ubuntu.com/ubuntu groovy-updates/universe Translation-en [64.8 kB]
Get:41 http://us.archive.ubuntu.com/ubuntu groovy-updates/universe amd64 DEP-11 Metadata [104 kB]
Get:42 http://us.archive.ubuntu.com/ubuntu groovy-updates/universe amd64 c-n-f Metadata [5,280 B]
Get:43 http://us.archive.ubuntu.com/ubuntu groovy-updates/multiverse i386 Packages [4,764 B]
Get:44 http://us.archive.ubuntu.com/ubuntu groovy-updates/multiverse amd64 Packages [14.0 kB]
Get:45 http://us.archive.ubuntu.com/ubuntu groovy-updates/multiverse amd64 DEP-11 Metadata [2,468 B]
Get:46 http://us.archive.ubuntu.com/ubuntu groovy-backports/universe amd64 DEP-11 Metadata [600 B]
Reading package lists... Done 
E: The repository 'http://ppa.launchpad.net/chris-lea/redis-server/ubuntu groovy Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'http://repo.zabbix.com/zabbix/5.2/ubuntu focal InRelease' doesn't support architecture 'i386'
ubuntu@Redis-server:~$

Step 2: Update the system

sudo apt-get update

Sample Output:

ubuntu@Redis-server:~$ sudo apt-get update
Ign:1 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu groovy InRelease 
Hit:2 http://us.archive.ubuntu.com/ubuntu groovy InRelease 
Hit:3 https://artifacts.elastic.co/packages/oss-6.x/apt stable InRelease 
Err:4 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu groovy Release 
404 Not Found [IP: 91.189.95.85 80]
Hit:5 https://repos.influxdata.com/ubuntu bionic InRelease 
Ign:6 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 InRelease 
Hit:7 http://us.archive.ubuntu.com/ubuntu groovy-updates InRelease 
Hit:8 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 Release 
Hit:9 http://repo.zabbix.com/zabbix/5.2/ubuntu focal InRelease 
Hit:11 http://us.archive.ubuntu.com/ubuntu groovy-backports InRelease 
Hit:12 https://packages.graylog2.org/repo/debian stable InRelease 
Hit:13 http://security.ubuntu.com/ubuntu groovy-security InRelease 
Reading package lists... Done
E: The repository 'http://ppa.launchpad.net/chris-lea/redis-server/ubuntu groovy Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'http://repo.zabbix.com/zabbix/5.2/ubuntu focal InRelease' doesn't support architecture 'i386'
ubuntu@Redis-server:~$

Step 3: Install Redis server on Ubuntu 

sudo apt-get install redis-server -y

Sample Output:

ubuntu@Redis-server:~$ sudo apt-get install redis-server -y
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following package was automatically installed and is no longer required:
virtualbox-guest-utils
Use 'sudo apt autoremove' to remove it.
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 199 not upgraded.
Need to get 1,097 kB of archives.
After this operation, 5,357 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu groovy/main amd64 libatomic1 amd64 10.2.0-13ubuntu1 [9,288 B]
Get:2 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 libjemalloc2 amd64 5.2.1-1ubuntu1 [235 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 liblua5.1-0 amd64 5.1.5-8.1build4 [99.9 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 liblzf1 amd64 3.6-2 [7,156 B]
Get:5 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 lua-bitop amd64 1.0.2-5 [6,680 B]
Get:6 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 lua-cjson amd64 2.1.0+dfsg-2.1 [17.4 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 redis-tools amd64 5:6.0.6-1 [677 kB]
Get:8 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 redis-server amd64 5:6.0.6-1 [43.6 kB]
Fetched 1,097 kB in 6s (172 kB/s) 
Selecting previously unselected package libatomic1:amd64.
(Reading database ... 192891 files and directories currently installed.)
Preparing to unpack .../0-libatomic1_10.2.0-13ubuntu1_amd64.deb ...
Unpacking libatomic1:amd64 (10.2.0-13ubuntu1) ...
Selecting previously unselected package libjemalloc2:amd64.
Preparing to unpack .../1-libjemalloc2_5.2.1-1ubuntu1_amd64.deb ...
Unpacking libjemalloc2:amd64 (5.2.1-1ubuntu1) ...
Selecting previously unselected package liblua5.1-0:amd64.
Preparing to unpack .../2-liblua5.1-0_5.1.5-8.1build4_amd64.deb ...
Unpacking liblua5.1-0:amd64 (5.1.5-8.1build4) ...
Selecting previously unselected package liblzf1:amd64.
Preparing to unpack .../3-liblzf1_3.6-2_amd64.deb ...
Unpacking liblzf1:amd64 (3.6-2) ...
Selecting previously unselected package lua-bitop:amd64.
Preparing to unpack .../4-lua-bitop_1.0.2-5_amd64.deb ...
Unpacking lua-bitop:amd64 (1.0.2-5) ...
Selecting previously unselected package lua-cjson:amd64.
Preparing to unpack .../5-lua-cjson_2.1.0+dfsg-2.1_amd64.deb ...
Unpacking lua-cjson:amd64 (2.1.0+dfsg-2.1) ...
Selecting previously unselected package redis-tools.
Preparing to unpack .../6-redis-tools_5%3a6.0.6-1_amd64.deb ...
Unpacking redis-tools (5:6.0.6-1) ...
Selecting previously unselected package redis-server.
Preparing to unpack .../7-redis-server_5%3a6.0.6-1_amd64.deb ...
Unpacking redis-server (5:6.0.6-1) ...
Setting up libjemalloc2:amd64 (5.2.1-1ubuntu1) ...
Setting up lua-cjson:amd64 (2.1.0+dfsg-2.1) ...
Setting up liblzf1:amd64 (3.6-2) ...
Setting up libatomic1:amd64 (10.2.0-13ubuntu1) ...
Setting up lua-bitop:amd64 (1.0.2-5) ...
Setting up liblua5.1-0:amd64 (5.1.5-8.1build4) ...
Setting up redis-tools (5:6.0.6-1) ...
Setting up redis-server (5:6.0.6-1) ...
Created symlink /etc/systemd/system/redis.service → /lib/systemd/system/redis-server.service.
Created symlink /etc/systemd/system/multi-user.target.wants/redis-server.service → /lib/systemd/system/redis-server.service.
Processing triggers for systemd (246.6-1ubuntu1) ...
Processing triggers for man-db (2.9.3-2) ...
Processing triggers for libc-bin (2.32-0ubuntu3) ...
ubuntu@Redis-server:~$

Step 4: Autostart Redis service on boot

sudo systemctl enable redis-server.service

Sample out:

ubuntu@Redis-server:~$ sudo systemctl enable redis-server.service
Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable redis-server
ubuntu@Redis-server:~$

Step 5: Verify Redis Version

redis-server --version

Sample Output:

ubuntu@Redis-server:~$ redis-server --version
Redis server v=6.0.6 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=ca474e00afe358bb
ubuntu@Redis-server:~$

Step 6: Configuring Redis on Ubuntu

Locate configuration file: /etc/redis/redis.conf 

– binding IP Address is located at 127.0.0.1 ::1

How To Install and Configure Redis on Ubuntu 20

There are other parameters, If you want to activate you can do it by uncommenting the line.

By default, Redis will stop writing new data when maxmemory is reached.

Whenever you made any changes to redis.conf file, reload or restart the Redis service.

sudo systemctl restart redis-server.service 
sudo systemctl status redis-server.service 

How To Install and Configure Redis on Ubuntu 20

Sample Output:

ubuntu@Redis-server:~$ sudo systemctl status redis-server.service 
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor>
Active: active (running) since Mon 2021-05-03 12:10:15 EDT; 11s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 6400 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=>
Main PID: 6401 (redis-server)
Tasks: 5 (limit: 4648)
Memory: 2.6M
CGroup: /system.slice/redis-server.service
└─6401 /usr/bin/redis-server 127.0.0.1:6379

May 03 12:10:15 Redis-server systemd[1]: Starting Advanced key-value store...
May 03 12:10:15 Redis-server systemd[1]: redis-server.service: Can't open PID >
May 03 12:10:15 Redis-server systemd[1]: Started Advanced key-value store.

If service didn’t start then check the Redis logs: /var/log/redis/redis-server.log

sudo tail /var/log/redis/redis-server.log

How To Install and Configure Redis on Ubuntu 20

As per the above screenshot, there is one issue found in Redis logs. 

→ To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.

sudo echo 'vm.overcommit_memory = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
sudo sysctl -p

Sample Output:

ubuntu@Redis-server:~$ sudo echo 'vm.overcommit_memory = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
ubuntu@Redis-server:~$ 
ubuntu@Redis-server:~$ sudo sysctl -p
vm.overcommit_memory = 1
ubuntu@Redis-server:~$

After you changed the vm.overcomit_memory parameter to be ‘1’, then you need to restart the Redis service and re-check the Redis log again. 

sudo systemctl restart redis-server.service && sudo systemctl status redis-server.service 

Re-check Redis-server logs

sudo tail -f /var/log/redis/redis-server.log

How To Install and Configure Redis on Ubuntu 20

→ To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

Sample output:

root@Redis-server:~# sudo echo never > /sys/kernel/mm/transparent_hugepage/enabled

root@Redis-server:~# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
root@Redis-server:~# sudo systemctl restart redis-server.service && sudo systemctl status redis-server.service

Recheck the Redis logs:

How To Install and Configure Redis on Ubuntu 20

Now the Issue is disappeared.

Step 7: (Optional) Configure firewall if it is enabled

sudo ufw allow 6379

Sample Output:

ubuntu@Redis-server:~$ sudo ufw allow 6379
Rules updated
Rules updated (v6)
ubuntu@Redis-server:~$

Step 8: Test the Redis connection 

Install Redis Client (Optional)

  • By default, the Redis client will get installed with the Redis server.
sudo apt-get update

sudo apt-get install redis-tools

Test the connection 

redis-cli -h 127.0.0.1

How To Install and Configure Redis on Ubuntu 20

End of Article, – How To Install and Configure Redis on Ubuntu 20.04.

See also:

List of monitoring tools 

Linux Blogs

AWS Cloud Blogs

Database Blogs

DevOps Blogs

Interview Questions & Answers

Docker Blogs

Google Cloud Blogs