KAHIBARO
Discord Login Register

16.3.2. Installing Redis

Getting Ready to Install Redis

This chapter walks you through installing Redis on different platforms and verifying that it works. You do not need previous Redis knowledge, but you should be comfortable running simple commands in a terminal.

We will cover:

Throughout, we will keep things simple so you can get Redis running quickly on your development machine.

Rule: Always install Redis from a trusted source (official package manager, official website, or well known container registry). Never download random binaries from unknown websites.


Installing Redis on Linux

Linux is the most common environment for running Redis in production. For development, you can usually use your distribution package manager.

Installing on Ubuntu / Debian

Use apt from the terminal.

  1. Update package lists:
bash
sudo apt update
  1. Install Redis:
bash
sudo apt install redis-server
  1. Check that Redis is installed:
bash
redis-server --version

You should see something like:

text
Redis server v=7.0.15 sha=... bits=64 ...

Starting and Stopping Redis (systemd)

On modern Ubuntu and Debian, Redis runs as a systemd service.

bash
sudo systemctl start redis-server
bash
sudo systemctl stop redis-server
bash
sudo systemctl restart redis-server
bash
sudo systemctl status redis-server

Look for the line Active: active (running) which means Redis is running.

Enable Redis on Boot

To start Redis automatically when the system boots:

bash
sudo systemctl enable redis-server

If you later want to disable auto start:

bash
sudo systemctl disable redis-server

Installing on CentOS / Rocky Linux / RHEL

Many RHEL based systems do not ship a recent Redis in their default repositories. A common approach is to use the Remi repository, which provides newer versions.

  1. Install EPEL and Remi repositories (example for CentOS 8 or similar):
bash
sudo dnf install epel-release
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
  1. Enable the Redis module from Remi:
bash
sudo dnf module enable redis:remi-7.0 -y
  1. Install Redis:
bash
sudo dnf install redis -y
  1. Start and enable Redis:
bash
sudo systemctl start redis
sudo systemctl enable redis
  1. Check version:
bash
redis-server --version

Building Redis from Source (Any Linux)

If your package manager provides an old version, you can compile Redis yourself.

  1. Install build tools (Ubuntu example):
bash
sudo apt update
sudo apt install build-essential tcl
  1. Download the latest stable Redis from the official website:
bash
curl -O https://download.redis.io/redis-stable.tar.gz
tar xzf redis-stable.tar.gz
cd redis-stable
  1. Compile:
bash
make
  1. Optionally run tests (this can take a while):
bash
make test
  1. Install binaries:
bash
sudo make install

This usually installs redis-server and redis-cli into /usr/local/bin.

  1. Start Redis quickly for development:
bash
redis-server

This starts Redis in the foreground. Press Ctrl + C to stop.

You can also provide a configuration file:

bash
redis-server /path/to/redis.conf

Installing Redis on macOS

On macOS, the easiest way is to use Homebrew. If you do not have Homebrew, first install it from https://brew.sh by following their instructions.

Installing with Homebrew

  1. Update Homebrew:
bash
brew update
  1. Install Redis:
bash
brew install redis
  1. Check the version:
bash
redis-server --version

You should see Redis version information printed.

Running Redis on macOS

There are two main ways to run Redis with Homebrew.

1. Run Redis Manually (Foreground)

Start the server:

bash
redis-server

You will see logs in your terminal. Press Ctrl + C to stop it.

This is good for quick experiments.

2. Run Redis as a Background Service

To run Redis in the background:

bash
brew services start redis

To stop the service:

bash
brew services stop redis

To restart:

bash
brew services restart redis

To see running services:

bash
brew services list

Look for a line like:

text
redis  started  your-username  ...

which means Redis is running.


Installing Redis on Windows

Redis does not officially support Windows natively anymore. For learning and development, you have three common options:

For this course, WSL or Docker is recommended, because both are very close to Linux environments.

Option 1: Redis on Windows with WSL

WSL lets you run a Linux distribution inside Windows.

Step 1: Install WSL and a Linux Distribution

In PowerShell (as Administrator):

powershell
wsl --install

By default, this installs Ubuntu. After reboot, follow the prompts to set up a username and password in Ubuntu.

Step 2: Install Redis inside WSL

Open the Ubuntu terminal from the Start menu and run:

bash
sudo apt update
sudo apt install redis-server

Start Redis:

bash
sudo service redis-server start

Check status:

bash
sudo service redis-server status

You can now use redis-cli inside WSL:

bash
redis-cli ping

Expected response:

text
PONG

Option 2: Redis on Windows with Docker

If you use Docker Desktop on Windows, you can run a Linux Redis container.

  1. Install Docker Desktop from https://www.docker.com/products/docker-desktop and make sure it is running.
  2. Pull the official Redis image:
bash
docker pull redis:latest
  1. Start a Redis container:
bash
docker run -d --name redis-dev -p 6379:6379 redis:latest

Explanation:

  1. Check running containers:
bash
docker ps
  1. To stop the container:
bash
docker stop redis-dev
  1. To start it again:
bash
docker start redis-dev

You can now connect to Redis from Windows using a Redis client on localhost:6379.


Basic Redis Configuration

Full configuration is covered later in the Redis chapter. For now, you only need minimal adjustments to get started safely in development.

Finding the Redis Configuration File

Common locations:

OS / Install methodTypical path
Ubuntu / Debian package/etc/redis/redis.conf
RHEL / CentOS package/etc/redis.conf
macOS Homebrew/usr/local/etc/redis.conf or similar
Source buildredis.conf in the source directory

You can always search for it, for example:

bash
sudo find / -name "redis.conf" 2>/dev/null

Starting Redis with a Specific Config

If you want to use a custom configuration file, you can copy the default redis.conf and then run:

bash
redis-server /path/to/your-redis.conf

For example:

bash
cp /etc/redis/redis.conf ~/dev-redis.conf
redis-server ~/dev-redis.conf

This is useful when you want different settings for development and production.

Making Basic Development Friendly Changes

In development, two very common config tweaks are:

  1. Bind to local interface only
  2. Disable or relax authentication (only on a trusted local machine)

Open your config file with a text editor, for example on Ubuntu:

bash
sudo nano /etc/redis/redis.conf

Bind Address

Look for a line like:

text
bind 127.0.0.1 ::1

This restricts Redis to accept connections only from the local machine. This is good during development.

If you see a line like:

text
# bind 127.0.0.1 ::1

uncomment it by removing the # to avoid listening on all interfaces.

Protected Mode

You may see:

text
protected-mode yes

Keep this as yes for safety in development.

Require Password

Config line:

text
# requirepass yourpassword

For simple local development, you can keep this commented, so no password is required. If you enable it:

text
requirepass verysecretpassword

Then you must authenticate in redis-cli:

bash
AUTH verysecretpassword

Rule: Never run Redis without a password on a server that is accessible from the internet. For production systems, always use authentication and proper firewall rules.

After changing the config, restart Redis:

On Ubuntu / Debian:

bash
sudo systemctl restart redis-server

On macOS (Homebrew):

bash
brew services restart redis

On Docker:

bash
docker restart redis-dev

Testing Your Redis Installation

After installation, you should verify that Redis is running and accepting commands.

Using redis-cli

redis-cli is the standard command line client that comes with Redis.

Simple Connection Test

In a terminal:

bash
redis-cli ping

If Redis is running on localhost:6379 with no password, you should see:

text
PONG

If you set a password:

bash
redis-cli
AUTH verysecretpassword
PING

Expected:

text
OK
PONG

Basic Commands

Try some simple operations.

  1. Set and get a key:
bash
redis-cli SET greeting "Hello, Redis!"
redis-cli GET greeting

Output:

text
"Hello, Redis!"
  1. Check key existence:
bash
redis-cli EXISTS greeting

If the key exists, Redis returns 1. If not, it returns 0.

  1. Delete a key:
bash
redis-cli DEL greeting
redis-cli EXISTS greeting

You should see 0 after delete.

  1. Use the interactive shell:
bash
redis-cli

Then inside the prompt:

text
127.0.0.1:6379> SET counter 1
OK
127.0.0.1:6379> INCR counter
(integer) 2
127.0.0.1:6379> GET counter
"2"
127.0.0.1:6379> EXIT

Connecting From an Application (High Level View)

Later in the course you will connect to Redis from languages like Python. A minimal Python example, just to test connectivity, looks like this:

python
import redis
client = redis.Redis(host="localhost", port=6379, db=0)
client.set("language", "Python")
value = client.get("language")
print(value)  # b'Python'

If this script runs without errors and prints b'Python' then Redis is working and your client library can connect.

You do not need to memorize this code now. It is only to show what a successful connection looks like from a program.


Common Installation Problems and Quick Fixes

Here are some frequent issues you may hit and how to resolve them.

Problem: `redis-server: command not found`

Possible causes and actions:

CauseFix
Package not installedInstall via apt, dnf, brew, or Docker as described above
Binary not in PATHUse full path, for example /usr/local/bin/redis-server
Wrong shell session (e.g. outside WSL)Make sure you run commands inside the correct environment or shell

To locate Redis:

bash
which redis-server

or

bash
command -v redis-server

If those commands return nothing, Redis is not installed in your current environment.

Problem: `Could not connect to Redis at 127.0.0.1:6379`

This usually means the server is not running, or is listening on a different host or port.

Checklist:

  1. Check if Redis is running:
    • On systemd based systems:
bash
     systemctl status redis-server
bash
     brew services list
bash
     docker ps
  1. If it is not running, start or restart it.
  2. Check the port in redis.conf. Look for:
text
   port 6379

If you changed the port, call:

bash
   redis-cli -p NEW_PORT ping

Problem: Authentication Error

If you see:

text
NOAUTH Authentication required.

It means requirepass is configured. Run:

bash
redis-cli
AUTH yourpassword
PING

If you forgot the password in a local development setup:

  1. Stop Redis
  2. Edit redis.conf and comment out requirepass
  3. Start Redis again

Do not do this on a shared or remote server.


Summary

In this chapter you learned how to:

With Redis installed and running successfully, you are ready to explore keys, values, and the powerful data structures that Redis provides in the next chapters.

Views: 7

Comments

Please login to add a comment.

Don't have an account? Register now!