How To Install Redis on Ubuntu 22.04

Redis:

Redis (REmote DIctionary Server) is an open source, in-memory, NoSQL key/value store that is used primarily as an application cache or quick-response database.

Getting started with Redis

1. System Update

sudo apt update
sudo apt upgrade -y

2. Add Redis Official APT Repository

Install required packages:

sudo apt-get install lsb-release curl gpg -y

Import Redis GPG key:

curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

Set correct permissions:

sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg

Add Redis repository to APT sources:

echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

Update APT cache:

sudo apt-get update

2. Add Redis Official APT Repository

sudo apt-get install redis -y

4. Enable Redis Service

sudo systemctl enable redis-server
sudo systemctl start redis-server
sudo systemctl status redis-server

5. Test Redis Service

redis-cli
ping

Expected output:

PONG

Exit:

exit

6. Configure Redis for systemd & Security

Open configuration file:

sudo nano /etc/redis/redis.conf

6.1 Enable systemd supervision

Search or manually add:

supervised systemd

6.1 Enable systemd supervision

Find:

# requirepass foobared

Uncomment and modify:

requirepass <YourStrongPassword>  #set your db password

6.3 (Optional) Enable Remote Access

Only if required for external applications:

bind 0.0.0.0

Save and exit (CTRL+O, Enter, CTRL+X)

Restart Redis:

sudo systemctl restart redis-server

6.3 (Optional) Enable Remote Access

redis-cli
AUTH <YourStrongPassword>
ping

Output:

PONG

Last updated