Redis is a high-performance in-memory data store used as a cache, database, and message broker. Thanks to its extremely low latency and simple architecture, Redis is widely adopted in web development, microservices, and high-load systems.
Installing Redis on Ubuntu usually takes only a few minutes, but it is important to configure the basic setup correctly from the start to ensure security and production readiness.
System Preparation
Before installing Redis, it is recommended to update the system packages. This reduces the risk of version conflicts and dependency issues during installation.
sudo apt update
sudo apt upgrade -yAfter updating, the system is ready to install Redis from the official Ubuntu repositories.
Installing Redis
Redis can be installed with a single command using the package manager:
sudo apt install redis-server -yOnce installed, Redis usually starts automatically as a system service. You can check its status using systemd:
sudo systemctl status redisIf the service is not active, you can start it manually:
sudo systemctl start redisTo enable Redis to start automatically on boot:
sudo systemctl enable redisRedis includes a built-in CLI client used for testing and administration. You can connect to the server with:
redis-cliThe simplest test is the ping command. If Redis is working correctly, it will respond with PONG:
pingYou can also test basic storage operations:
set key "Hello Redis"
get keyIf Redis returns the stored value, the installation is working correctly. The main Redis configuration file is located at:
/etc/redis/redis.confYou can edit it using a text editor:
sudo nano /etc/redis/redis.confThis file defines key settings such as network interface, port, authentication, and memory usage. By default, Redis is configured to accept only local connections, which is safer for development environments.
For production use, it is common to enable password authentication:
requirepass StrongPassword123After making changes, restart the service:
sudo systemctl restart redisSecurity and Remote Access
By default, Redis is only accessible from localhost, which helps prevent unauthorized access. If remote access is required, you need to modify the bind setting:
bind 0.0.0.0However, exposing Redis directly to the internet is strongly discouraged. If remote access is necessary, you should always enable authentication and properly configure firewall rules.
To allow traffic through the firewall:
sudo ufw allow 6379In production environments, it is better to restrict access to trusted IP addresses only. Since Redis stores data in memory, it is important to control memory usage. You can define a memory limit in the configuration file:
maxmemory 256mbYou can also configure how Redis behaves when memory is full:
maxmemory-policy allkeys-lruThis policy ensures that Redis removes the least recently used keys when it reaches the memory limit, helping prevent service crashes.Installing Redis on Ubuntu is quick and straightforward, but proper configuration is essential for secure and stable operation. Even a basic setup allows Redis to function as a high-speed cache or in-memory data store.
In modern application architectures, Redis often becomes a critical component, significantly improving performance and reducing the load on primary databases.