How to Install Redis on Linux: Step-by-Step Guide
To install
Redis on Linux, use your system's package manager like apt for Ubuntu or yum for CentOS. Run sudo apt update then sudo apt install redis-server on Ubuntu, or sudo yum install redis on CentOS, then start the Redis service.Syntax
Use your Linux distribution's package manager to install Redis. The commands below show the general syntax:
- Ubuntu/Debian:
sudo apt updateupdates package lists, thensudo apt install redis-serverinstalls Redis. - CentOS/RHEL:
sudo yum install redisinstalls Redis directly. - After installation, start Redis with
sudo systemctl start redisand enable it to run on boot withsudo systemctl enable redis.
bash
sudo apt update sudo apt install redis-server sudo systemctl start redis sudo systemctl enable redis
Example
This example shows how to install Redis on Ubuntu, start the service, and check its status.
bash
sudo apt update sudo apt install -y redis-server sudo systemctl start redis sudo systemctl enable redis sudo systemctl status redis
Output
● redis.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2024-06-20 10:00:00 UTC; 10s ago
Main PID: 1234 (redis-server)
Tasks: 4 (limit: 4915)
Memory: 1.5M
CGroup: /system.slice/redis.service
└─1234 /usr/bin/redis-server 127.0.0.1:6379
Common Pitfalls
Common mistakes when installing Redis on Linux include:
- Not updating package lists before installation, causing outdated versions.
- Forgetting to start or enable the Redis service, so Redis won't run automatically.
- Using incorrect package names depending on the Linux distribution.
- Not checking firewall settings that may block Redis default port 6379.
bash
sudo apt install redis-server
sudo systemctl start redis
# Wrong: missing 'sudo apt update' may install old version
# Correct way:
sudo apt update
sudo apt install redis-server
sudo systemctl start redis
sudo systemctl enable redisQuick Reference
| Command | Description |
|---|---|
| sudo apt update | Refresh package lists on Ubuntu/Debian |
| sudo apt install redis-server | Install Redis on Ubuntu/Debian |
| sudo yum install redis | Install Redis on CentOS/RHEL |
| sudo systemctl start redis | Start Redis service |
| sudo systemctl enable redis | Enable Redis to start on boot |
| sudo systemctl status redis | Check Redis service status |
Key Takeaways
Always update your package list before installing Redis to get the latest version.
Use the correct package manager commands for your Linux distribution.
Start and enable the Redis service to ensure it runs properly.
Check Redis service status to confirm successful installation.
Be aware of firewall settings that might block Redis connections.