Redis Installation
Redis supports multiple operating systems. This lesson covers detailed installation steps on Linux, Windows, and Mac.
Installing Redis on Linux
Linux is the best platform for running Redis. For production environments, Linux is recommended.
Ubuntu/Debian Installation
Method 1: Using apt (Recommended for Beginners)
# Update package list
sudo apt update
# Install Redis server
sudo apt install redis-server -y
# Start Redis service
sudo systemctl start redis-server
# Enable auto-start on boot
sudo systemctl enable redis-server
Method 2: Compile from Source (Recommended for Production)
# Install build dependencies
sudo apt update
sudo apt install build-essential tcl -y
# Download Redis source code (using 7.0 as example)
cd /tmp
wget https://download.redis.io/redis-7.0.11.tar.gz
# Extract
tar xzf redis-7.0.11.tar.gz
cd redis-7.0.11
# Compile
make
# Test compilation (optional, takes a few minutes)
make test
# Install to system directories
sudo make install
CentOS/RHEL Installation
Method 1: Using yum
# Install EPEL repository
sudo yum install epel-release -y
# Install Redis
sudo yum install redis -y
# Start Redis
sudo systemctl start redis
# Enable auto-start on boot
sudo systemctl enable redis
Method 2: Compile from Source
# Install build dependencies
sudo yum groupinstall "Development Tools" -y
sudo yum install tcl -y
# Download, compile, install (same as Ubuntu)
cd /tmp
wget https://download.redis.io/redis-7.0.11.tar.gz
tar xzf redis-7.0.11.tar.gz
cd redis-7.0.11
make
sudo make install
Manually Starting Redis (After Source Installation)
# Start Redis server (foreground)
redis-server
# Run in background (recommended)
redis-server --daemonize yes
# Start with a config file
redis-server /etc/redis/redis.conf
Installing Redis on Windows
Redis is not officially supported on Windows, but Microsoft maintains a Windows port.
Method 1: Using Installer (Recommended)
Step 1: Download Redis
Visit GitHub to download the latest version:
https://github.com/microsoftarchive/redis/releases
Download Redis-x64-3.2.100.msi (or a newer version)
Step 2: Install
- Double-click the msi file
- Choose an installation path (e.g.,
C:\Program Files\Redis) - Check "Add Redis to PATH"
- Check "Install as Windows Service"
- Click Install to complete
Step 3: Verify
Open Command Prompt:
redis-cli ping
If it returns PONG, the installation was successful.
Method 2: Using WSL (Recommended for Developers)
WSL (Windows Subsystem for Linux) can run the native Linux version of Redis.
# Install WSL (PowerShell as Administrator)
wsl --install
# After reboot, install Redis in WSL
sudo apt update
sudo apt install redis-server -y
# Start Redis
sudo service redis-server start
Method 3: Using Docker
# Pull Redis image
docker pull redis
# Run Redis container
docker run -d -p 6379:6379 --name redis redis
# Connect to Redis
docker exec -it redis redis-cli
Installing Redis on Mac
Method 1: Using Homebrew (Recommended)
# Install Homebrew (if not already installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Redis
brew install redis
# Start Redis service
brew services start redis
# Or start in foreground
redis-server
Method 2: Compile from Source
# Install build tools (if not already installed)
xcode-select --install
# Download, compile, install
cd /tmp
wget https://download.redis.io/redis-7.0.11.tar.gz
tar xzf redis-7.0.11.tar.gz
cd redis-7.0.11
make
sudo make install
Installing Redis with Docker (Cross-platform)
Docker is the easiest way to install Redis, suitable for development and testing.
Pulling the Image
# Pull the latest version
docker pull redis
# Pull a specific version
docker pull redis:7.0
docker pull redis:6.2
Running the Container
# Basic run
docker run -d -p 6379:6379 --name redis redis
# Run with password
docker run -d -p 6379:6379 --name redis redis --requirepass yourpassword
# Persistent storage
docker run -d -p 6379:6379 -v /data/redis:/data --name redis redis --appendonly yes
# Use a config file
docker run -d -p 6379:6379 -v /path/to/redis.conf:/etc/redis/redis.conf --name redis redis /etc/redis/redis.conf
Connecting to Redis
# Enter Redis CLI
docker exec -it redis redis-cli
# Connect with password
docker exec -it redis redis-cli -a yourpassword
Verifying the Installation
No matter which installation method you used, verify that Redis is properly installed.
1. Check Redis Service Status
Linux (systemd):
sudo systemctl status redis
# or
sudo systemctl status redis-server
Mac (Homebrew):
brew services list
Windows:
# Check service status
Get-Service Redis
2. Connect with redis-cli
# Connect to local Redis
redis-cli
# Test after connecting
ping
PONG
set test "Hello Redis"
OK
get test
"Hello Redis"
exit
3. Check Redis Version
redis-server --version
# Output: Redis server v=7.0.11 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64
redis-cli --version
# Output: redis-cli 7.0.11
4. Check Redis Info
redis-cli info server
Key information:
redis_version:7.0.11
redis_mode:standalone
os:Linux 5.15.0 x86_64
tcp_port:6379
uptime_in_seconds:3600
Redis Directory Structure
Directory structure after source installation:
/usr/local/bin/
├── redis-server # Redis server
├── redis-cli # Redis command-line client
├── redis-benchmark # Redis performance benchmark tool
├── redis-check-rdb # RDB file checker
└── redis-check-aof # AOF file checker
Config file locations:
- apt/yum installation:
/etc/redis/redis.conf - Source installation: Must copy from source directory or create manually
- Homebrew installation:
/usr/local/etc/redis.conf
Common Installation Issues
Issue 1: Port Already in Use
Error message:
Creating Server TCP listening socket *:6379: bind: Address already in use
Solution:
# Check port usage
sudo lsof -i :6379
# or
sudo netstat -nltp | grep 6379
# Stop the process using the port
sudo kill -9 <PID>
# Or start with a different port
redis-server --port 6380
Issue 2: Insufficient Permissions
Error message:
Can't open the log file: Permission denied
Solution:
# Create Redis user
sudo useradd -r -s /bin/false redis
# Change data directory permissions
sudo chown -R redis:redis /var/lib/redis
sudo chown -R redis:redis /var/log/redis
Issue 3: Insufficient Memory
Error message:
OOM command not allowed when used memory > 'maxmemory'.
Solution:
# Modify config file to set max memory
maxmemory 256mb
# Or specify at startup
redis-server --maxmemory 256mb
Issue 4: Windows Firewall
Solution:
# Add firewall rule (PowerShell as Administrator)
New-NetFirewallRule -DisplayName "Redis" -Direction Inbound -LocalPort 6379 -Protocol TCP -Action Allow
Startup Parameters
redis-server [config file] [options]
Common options:
--port 6379 # Specify port
--bind 0.0.0.0 # Bind IP address
--daemonize yes # Run in background
--logfile /var/log/redis.log # Log file
--dir /var/lib/redis # Data directory
--maxmemory 256mb # Max memory
--requirepass password # Set password
--appendonly yes # Enable AOF persistence
❓ FAQ
redis-server --port 6380 --config-file /etc/redis/redis-6380.confQ: How do I uninstall Redis? A:
- apt:
sudo apt remove redis-server- yum:
sudo yum remove redis- Source:
sudo make uninstall(in the source directory)- Homebrew:
brew uninstall redis
📖 Summary
- Linux is the best platform for Redis; compiling from source is recommended
- Windows: use the installer, WSL, or Docker
- Mac: Homebrew is recommended
- Docker is great for development and testing, works cross-platform
- After installation, verify with
redis-cli ping - For production, configure passwords, firewalls, and memory limits
📝 Exercises
- Installation practice: Install Redis on your system and verify it works
- Version check: Check your Redis version and learn its key features
- Multi-instance practice: Try starting two Redis instances on ports 6379 and 6380
Next Lesson
In the next lesson, we will learn Redis Quick Start — starting Redis and running your first commands.



