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 upgrade -y
After 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:
Once installed, Redis usually starts automatically as a system service. You can check its status using systemd:
If the service is not active, you can start it manually:
To enable Redis to start automatically on boot:
Redis includes a built-in CLI client used for testing and administration. You can connect to the server with:
The simplest test is the ping command. If Redis is working correctly, it will respond with PONG:
You can also test basic storage operations:
get key
If Redis returns the stored value, the installation is working correctly. The main Redis configuration file is located at:
You can edit it using a text editor:
This 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:
After making changes, restart the service:
Security 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:
However, 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:
In 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:
You can also configure how Redis behaves when memory is full:
This 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.