16.3.2. Installing Redis
Table of Contents
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:
- Installing Redis on Linux, macOS, and Windows
- Running Redis as a background service
- Basic configuration and testing your installation
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.
- Update package lists:
sudo apt update- Install Redis:
sudo apt install redis-server- Check that Redis is installed:
redis-server --versionYou should see something like:
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.
- Start Redis:
sudo systemctl start redis-server- Stop Redis:
sudo systemctl stop redis-server- Restart Redis:
sudo systemctl restart redis-server- Check status:
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:
sudo systemctl enable redis-serverIf you later want to disable auto start:
sudo systemctl disable redis-serverInstalling 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.
- Install EPEL and Remi repositories (example for CentOS 8 or similar):
sudo dnf install epel-release
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm- Enable the Redis module from Remi:
sudo dnf module enable redis:remi-7.0 -y- Install Redis:
sudo dnf install redis -y- Start and enable Redis:
sudo systemctl start redis
sudo systemctl enable redis- Check version:
redis-server --versionBuilding Redis from Source (Any Linux)
If your package manager provides an old version, you can compile Redis yourself.
- Install build tools (Ubuntu example):
sudo apt update
sudo apt install build-essential tcl- Download the latest stable Redis from the official website:
curl -O https://download.redis.io/redis-stable.tar.gz
tar xzf redis-stable.tar.gz
cd redis-stable- Compile:
make- Optionally run tests (this can take a while):
make test- Install binaries:
sudo make install
This usually installs redis-server and redis-cli into /usr/local/bin.
- Start Redis quickly for development:
redis-server
This starts Redis in the foreground. Press Ctrl + C to stop.
You can also provide a configuration file:
redis-server /path/to/redis.confInstalling 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
- Update Homebrew:
brew update- Install Redis:
brew install redis- Check the version:
redis-server --versionYou 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:
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:
brew services start redisTo stop the service:
brew services stop redisTo restart:
brew services restart redisTo see running services:
brew services listLook for a line like:
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:
- Use the Windows Subsystem for Linux (WSL)
- Use Docker
- Use the memurai project or older community ports (not recommended for long term learning)
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):
wsl --installBy 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:
sudo apt update
sudo apt install redis-serverStart Redis:
sudo service redis-server startCheck status:
sudo service redis-server status
You can now use redis-cli inside WSL:
redis-cli pingExpected response:
PONGOption 2: Redis on Windows with Docker
If you use Docker Desktop on Windows, you can run a Linux Redis container.
- Install Docker Desktop from https://www.docker.com/products/docker-desktop and make sure it is running.
- Pull the official Redis image:
docker pull redis:latest- Start a Redis container:
docker run -d --name redis-dev -p 6379:6379 redis:latestExplanation:
-druns in detached mode--name redis-devnames the container-p 6379:6379exposes port 6379 to your Windows host
- Check running containers:
docker ps- To stop the container:
docker stop redis-dev- To start it again:
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 method | Typical path |
|---|---|
| Ubuntu / Debian package | /etc/redis/redis.conf |
| RHEL / CentOS package | /etc/redis.conf |
| macOS Homebrew | /usr/local/etc/redis.conf or similar |
| Source build | redis.conf in the source directory |
You can always search for it, for example:
sudo find / -name "redis.conf" 2>/dev/nullStarting Redis with a Specific Config
If you want to use a custom configuration file, you can copy the default redis.conf and then run:
redis-server /path/to/your-redis.confFor example:
cp /etc/redis/redis.conf ~/dev-redis.conf
redis-server ~/dev-redis.confThis is useful when you want different settings for development and production.
Making Basic Development Friendly Changes
In development, two very common config tweaks are:
- Bind to local interface only
- Disable or relax authentication (only on a trusted local machine)
Open your config file with a text editor, for example on Ubuntu:
sudo nano /etc/redis/redis.confBind Address
Look for a line like:
bind 127.0.0.1 ::1This restricts Redis to accept connections only from the local machine. This is good during development.
If you see a line like:
# bind 127.0.0.1 ::1
uncomment it by removing the # to avoid listening on all interfaces.
Protected Mode
You may see:
protected-mode yes
Keep this as yes for safety in development.
Require Password
Config line:
# requirepass yourpasswordFor simple local development, you can keep this commented, so no password is required. If you enable it:
requirepass verysecretpassword
Then you must authenticate in redis-cli:
AUTH verysecretpasswordRule: 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:
sudo systemctl restart redis-serverOn macOS (Homebrew):
brew services restart redisOn Docker:
docker restart redis-devTesting 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:
redis-cli ping
If Redis is running on localhost:6379 with no password, you should see:
PONGIf you set a password:
redis-cli
AUTH verysecretpassword
PINGExpected:
OK
PONGBasic Commands
Try some simple operations.
- Set and get a key:
redis-cli SET greeting "Hello, Redis!"
redis-cli GET greetingOutput:
"Hello, Redis!"- Check key existence:
redis-cli EXISTS greeting
If the key exists, Redis returns 1. If not, it returns 0.
- Delete a key:
redis-cli DEL greeting
redis-cli EXISTS greeting
You should see 0 after delete.
- Use the interactive shell:
redis-cliThen inside the prompt:
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> EXITConnecting 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:
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:
| Cause | Fix |
|---|---|
| Package not installed | Install via apt, dnf, brew, or Docker as described above |
Binary not in PATH | Use 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:
which redis-serveror
command -v redis-serverIf 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:
- Check if Redis is running:
- On systemd based systems:
systemctl status redis-server- With Homebrew:
brew services list- With Docker:
docker ps- If it is not running, start or restart it.
- Check the port in
redis.conf. Look for:
port 6379If you changed the port, call:
redis-cli -p NEW_PORT pingProblem: Authentication Error
If you see:
NOAUTH Authentication required.
It means requirepass is configured. Run:
redis-cli
AUTH yourpassword
PINGIf you forgot the password in a local development setup:
- Stop Redis
- Edit
redis.confand comment outrequirepass - Start Redis again
Do not do this on a shared or remote server.
Summary
In this chapter you learned how to:
- Install Redis on Linux, macOS, and Windows (using WSL or Docker)
- Start, stop, and restart the Redis server
- Locate and use the basic Redis configuration file
- Test your installation with
redis-cliusing commands likePING,SET,GET, andDEL - Recognize and fix some common installation problems
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
KAHIBARO