How to Install Redis In-Memory Database on Ubuntu 26.04
02 Apr, 2026
Introduction
Redis is an open-source, in-memory data structure store that functions as a database, cache, and message broker. Unlike traditional databases that store data on disk, Redis keeps data in memory, enabling sub-millisecond response times for read and write operations. The database supports various data structures including strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis powers real-time applications like session management, leaderboards, rate limiting, job queues, and full-page caching for high-traffic web services.
This guide shows you how to install Redis on Ubuntu 26.04.
Prerequisites
Before you start:
- Deploy an Ubuntu 26.04 server with at least 1GB of RAM.
- SSH to your server using PuTTY for Windows or Open SSH for Linux and Mac OS.
- Create a non-root user with sudo privileges.
Install Redis from Ubuntu Repository
The Redis package is available by default on the Ubuntu repositories. Installing from the official repository provides a stable version tested for Ubuntu compatibility.
-
Refresh your system's package list to ensure you get the latest available versions.
console$ sudo apt update -
Install the Redis server package.
console$ sudo apt install -y redis-serverOutput:
Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: libjemalloc2 redis-tools Suggested packages: ruby-redis The following NEW packages will be installed: libjemalloc2 redis-server redis-tools 0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded. Need to get 1,234 kB of archives. After this operation, 8.45 MB of additional disk space will be used. -
Verify the Redis version.
console$ redis-server --versionOutput:
Redis server v=8.0.3 sha=00000000:0 malloc=jemalloc-5.3.0 bits=64 build=abc123def456
Manage Redis Service
Redis runs as a system service on Ubuntu under the name redis-server. You can manage this service using specific commands to start, stop, restart, and check the Redis status. These commands ensure your Redis installation runs smoothly and make maintenance easier on your system.
Check Redis Service Status
$ sudo systemctl status redis-server
Output:
● redis-server.service - Advanced key-value store
Loaded: loaded (/usr/lib/systemd/system/redis-server.service; enabled; preset: enabled)
Active: active (running) since Thu 2026-03-12 14:22:10 UTC; 1min 5s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 12456 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 2271)
Memory: 8.9M (peak: 9.2M)
CPU: 234ms
CGroup: /system.slice/redis-server.service
└─12456 "/usr/bin/redis-server *:6379"
Press Ctrl + C.
Start Redis Service
$ sudo systemctl start redis-server
Stop Redis Service
$ sudo systemctl stop redis-server
Restart Redis Service
$ sudo systemctl restart redis-server
Enable Redis to Start on Boot
$ sudo systemctl enable redis-server
Output:
Synchronizing state of redis-server.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable redis-server
Test Redis Locally
Before configuring remote access, test that Redis works correctly on your local server. The redis-cli command-line tool connects to Redis and executes commands.
-
Connect to Redis using the command-line interface.
console$ redis-cliOutput:
127.0.0.1:6379> -
Set a test key-value pair.
127.0.0.1:6379> set test_key "Hello Redis"Output:
OK -
Retrieve the value.
127.0.0.1:6379> get test_keyOutput:
"Hello Redis" -
List all keys in the database.
127.0.0.1:6379> keys *Output:
1) "test_key" -
Exit the Redis CLI.
127.0.0.1:6379> exitOutput:
$
Configure Redis with Password Authentication
By default, Redis does not require a password for connections. Securing Redis with a password prevents unauthorized access from remote clients.
-
Open the Redis configuration file with Nano.
console$ sudo nano /etc/redis/redis.conf -
Locate the
requirepassdirective.INI# requirepass foobared -
Uncomment the line and change the password to a strong value.
INIrequirepass your_strong_password_here -
Save and close the
/etc/redis/redis.conffile by pressing Ctrl + X + Y. -
Restart Redis to apply the password change.
console$ sudo systemctl restart redis-server -
Test the password authentication.
console$ redis-cliOutput:
127.0.0.1:6379> -
Try to run a command without authenticating.
127.0.0.1:6379> get test_keyOutput:
(error) NOAUTH Authentication required. -
Authenticate with the password.
127.0.0.1:6379> AUTH your_strong_password_hereOutput:
OK -
Retrieve the value again.
127.0.0.1:6379> get test_keyOutput:
"Hello Redis" -
Exit the Redis CLI.
127.0.0.1:6379> exit
Configure Redis to Accept Remote Connections
By default, Redis binds only to localhost for security reasons. To allow remote clients to connect, you need to modify the bind address in the configuration file.
-
Open the Redis configuration file for editing.
console$ sudo nano /etc/redis/redis.conf -
Locate the
binddirective.INIbind 127.0.0.1 -::1 -
Change the bind address to
0.0.0.0to listen on all network interfaces.INIbind 0.0.0.0 -
Save and close the
/etc/redis/redis.conffile by pressing Ctrl + X + Y. -
Restart Redis to apply the binding change.
console$ sudo systemctl restart redis-server
Configure Firewall for Redis
If UFW (Uncomplicated Firewall) is active on your Ubuntu server, you need to allow traffic on port 6379, which is the default port Redis uses.
-
Check the UFW status.
console$ sudo ufw statusOutput:
Status: active -
Allow Redis port 6379.
console$ sudo ufw allow 6379/tcpOutput:
Rule added Rule added (v6) -
Verify the firewall rule.
console$ sudo ufw statusOutput:
Status: active To Action From -- ------ ---- 6379/tcp ALLOW Anywhere 6379/tcp (v6) ALLOW Anywhere (v6)
Test Redis Remotely
From a remote machine with Redis CLI installed, test that you can connect to your Redis server using the password.
-
On the remote machine, connect to your Redis server.
console$ redis-cli -h your_server_ip -p 6379 -a your_strong_password_hereOutput:
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. your_server_ip:6379> -
Set a new key from the remote connection.
your_server_ip:6379> set remote_key "Connected from remote client"Output:
OK -
Retrieve the key.
your_server_ip:6379> get remote_keyOutput:
"Connected from remote client" -
Exit the remote Redis CLI.
your_server_ip:6379> exit
Configure Redis Memory Management
Redis stores all data in memory, so you should configure maximum memory limits and eviction policies to prevent out-of-memory crashes.
-
Open the Redis configuration file for editing.
console$ sudo nano /etc/redis/redis.conf -
Locate the
maxmemorydirective.INI# maxmemory <bytes> -
Set maximum memory to 256MB for a small server.
INImaxmemory 256mb -
Locate the
maxmemory-policydirective.INI# maxmemory-policy noeviction -
Change the eviction policy to
allkeys-lruwhich removes least recently used keys when memory fills up.INImaxmemory-policy allkeys-lru -
Save and close the
/etc/redis/redis.conffile by pressing Ctrl + X + Y. -
Restart Redis to apply memory settings.
console$ sudo systemctl restart redis-server
Monitor Redis Performance
Redis provides built-in commands to monitor performance metrics, connected clients, and memory usage.
-
Connect to Redis locally.
console$ redis-cli -a your_strong_password_here -
Check Redis statistics.
127.0.0.1:6379> INFO statsOutput:
# Stats total_connections_received:5 total_commands_processed:12 instantaneous_ops_per_sec:0 total_net_input_bytes:456 total_net_output_bytes:1234 rejected_connections:0 -
Check memory usage.
127.0.0.1:6379> INFO memoryOutput:
# Memory used_memory:8923456 used_memory_human:8.51M used_memory_rss:12345678 used_memory_peak:9234567 used_memory_peak_human:8.81M maxmemory:268435456 maxmemory_human:256.00M maxmemory_policy:allkeys-lru mem_fragmentation_ratio:1.38 -
Check connected clients.
127.0.0.1:6379> INFO clientsOutput:
# Clients connected_clients:2 client_recent_max_input_buffer:2048 client_recent_max_output_buffer:0 blocked_clients:0 tracking_clients:0 -
Exit the Redis CLI.
127.0.0.1:6379> exit
Test Redis Persistence
Redis can persist data to disk using RDB (Redis Database) snapshots or AOF (Append Only File) logging. Verify that your data survives a service restart.
-
Set a persistent test key.
console$ redis-cli -a your_strong_password_here set persistent_key "This data will survive restart"Output:
OK -
Restart the Redis service.
console$ sudo systemctl restart redis-server -
Retrieve the persistent key after restart.
console$ redis-cli -a your_strong_password_here get persistent_keyOutput:
"This data will survive restart"
Your Redis installation maintains data across restarts.
Conclusion
In this guide, you have installed Redis on Ubuntu 26.04 using apt, secured the database with password authentication, configured remote access, opened the firewall port, and managed memory limits with eviction policies. You also tested local and remote connections, monitored performance metrics, and verified data persistence across service restarts. Now that you have Redis running, consider integrating it with web frameworks like Django or Node.js for session storage, use it as a cache layer in front of PostgreSQL or MySQL, or implement real-time features like leaderboards and message queues using Redis data structures.