How To Install Redis on Ubuntu 26.04 LTS

Install Redis on Ubuntu 26.04

Plenty of Redis installs work fine on day one and fall over on day ninety. The usual story goes like this. Someone runs apt install, sees PONG, and moves on. Months later a traffic spike arrives, the instance eats all the RAM, the kernel’s OOM killer steps in, and sessions vanish. Or worse, port 6379 was open to the internet the whole time and nobody noticed until a crypto miner showed up in the process list.

Ubuntu 26.04 LTS (Resolute Raccoon) makes the first step easy. Redis 8.0.x ships in the default archive, so there is no third-party repository to babysit. The real work comes after the package lands: binding, authentication, persistence, memory limits, kernel settings, and monitoring. That is what separates a demo from a server you can leave alone.

This guide covers the whole path. It starts with installation and verification, then moves through configuration, security, tuning, and the failures that tend to show up at 2 AM. It also deals with a question that has become more common lately: should you run Redis or its fork, Valkey? Commands are written for Ubuntu 26.04, with notes for Debian and AlmaLinux where they differ.

What Ubuntu 26.04 Ships for Redis

Ubuntu 26.04 carries Redis 8.0.x in its default repositories. One guide that tested the install reports package version 5:8.0.5-1. Check your own mirror, because point releases move.

The upstream Redis project also publishes an APT repository at packages.redis.io, with a newer 8.x branch. As of the sources checked, that repository covers Ubuntu 24.04 and 22.04, and there is no native resolute repository for 26.04 yet. Redis documents the APT repository using $(lsb_release -cs) as the suite name, so on 26.04 that line would point to a suite that may not exist. Check before you try it.

Practical conclusion: on 26.04, use Ubuntu’s own package. You get security updates through the normal apt upgrade flow, and you avoid a repository that may not match your release.

Licensing is worth a moment. Redis 8 is offered under RSALv2, SSPLv1 or AGPLv3 at the user’s choice, while older versions were BSD-licensed. For most internal deployments this changes nothing. If you resell Redis as a managed service, read the terms or talk to legal.

Redis or Valkey?

Valkey is a Linux Foundation fork taken from Redis OSS 7.2.4, right before Redis moved to source-available licences. Ubuntu 26.04 packages it in main, so it gets Canonical security support. The 26.04 archive has carried the 9.0 line, with updates such as 9.0.4 and 9.0.6.

If your application only needs the Redis protocol for caching, sessions, queues or rate limiting, Valkey is a reasonable pick. If you rely on newer Redis 8 features such as its bundled modules and data structures, stay with Redis. Everything below applies to Redis, and most of the configuration carries over to Valkey with renamed files and services.

Prerequisites

Before touching anything, confirm the basics.

  • Ubuntu 26.04 LTS, fresh or existing, with a non-root user that has sudo rights.
  • At least 1 GB of RAM for testing. Production sizing depends on your dataset, covered later.
  • Network access to Ubuntu mirrors.
  • A clear idea of whether Redis is local-only (one app server) or must be reached over a private network.

Check the release first.

lsb_release -a
uname -r
free -h

Then bring the system current.

sudo apt update
sudo apt upgrade -y

A reboot is sensible if the kernel was updated. Do it now, not after Redis holds data.

Step 1: Install Redis on Ubuntu 26.04

Install the server and the client tools.

sudo apt install -y redis-server redis-tools

The redis-server package pulls in the daemon, and redis-tools supplies redis-cli, redis-benchmark and redis-check-aof. Installing both explicitly avoids surprises on minimal images.

Confirm what you got.

redis-server --version
apt policy redis-server

The apt policy output shows the installed and candidate versions and which repository supplied them. Make a habit of reading it. It saves arguments later about “which Redis is this”.

Step 2: Verify the Service

The package registers a systemd unit and starts it automatically.

sudo systemctl status redis-server
sudo systemctl enable redis-server

On Debian-family systems the unit is often aliased as redis, so systemctl status redis may also work. Then test a round trip.

redis-cli ping

You should see PONG. Try a write.

redis-cli set testkey "hello"
redis-cli get testkey
redis-cli del testkey

Check what is listening.

sudo ss -tlnp | grep 6379

You want 127.0.0.1:6379 (and possibly [::1]:6379). If you see 0.0.0.0:6379 or *:6379, stop and fix the binding before anything else. The security section below explains why.

Step 3: Understand the Config File

The main configuration lives at /etc/redis/redis.conf. Before editing, make a backup.

sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.orig

The file is long and heavily commented. Most of it can stay as is. The directives that matter on day one are these.

Directive Purpose Typical production value
bind Interfaces Redis listens on 127.0.0.1 ::1 or a private IP
protected-mode Blocks external clients with no auth yes
requirepass / ACLs Authentication Strong secret or ACL users
maxmemory Memory ceiling 60 to 75% of RAM for a cache
maxmemory-policy Eviction behavior allkeys-lru for cache
appendonly AOF persistence yes if data matters
supervised Init system integration systemd

On Ubuntu the package normally sets supervised systemd already. Verify with grep -E '^(supervised|bind|protected-mode)' /etc/redis/redis.conf.

After every edit, restart and read the log rather than assuming success.

sudo systemctl restart redis-server
sudo journalctl -u redis-server -n 30 --no-pager

Step 4: Lock Down Access

Redis was designed for trusted networks. It has no encryption by default and, historically, no authentication. Treat an exposed instance as a compromised one. Attackers scan the entire IPv4 space for port 6379 constantly, and a classic attack uses CONFIG SET dir and CONFIG SET dbfilename to write an SSH key or a cron file to disk.

Bind to the right interface

For a single server running the app and Redis together, keep it on loopback.

bind 127.0.0.1 ::1
protected-mode yes
port 6379

If app servers on a private network need access, bind to the private address as well.

bind 127.0.0.1 10.0.0.5

Never use bind 0.0.0.0 without a firewall and authentication in front of it. Even then, think twice.

Set authentication with ACLs

The old requirepass approach still works, yet ACLs are better. They let you create separate users with limited commands and key patterns, so a leaked app credential cannot run FLUSHALL or CONFIG.

Generate a strong password.

openssl rand -base64 32

Then, in /etc/redis/redis.conf, you can keep a simple default password.

requirepass YOUR_LONG_RANDOM_PASSWORD

Or define users at runtime and persist them.

redis-cli
127.0.0.1:6379> ACL SETUSER appuser on >APP_PASSWORD ~app:* +@read +@write +@connection -@dangerous
127.0.0.1:6379> ACL LIST
127.0.0.1:6379> ACL SAVE

ACL SAVE only works when an ACL file is configured, so add this to the config first.

aclfile /etc/redis/users.acl

Create the file with correct ownership.

sudo touch /etc/redis/users.acl
sudo chown redis:redis /etc/redis/users.acl
sudo chmod 640 /etc/redis/users.acl

Be careful with the ordering here. When you use an ACL file, user definitions should live in that file and not be mixed with user lines inside redis.conf. Mixing the two makes Redis refuse to start. That one catches people regularly.

Test the new user.

redis-cli --user appuser --pass 'APP_PASSWORD' ping

Passing the password on the command line triggers a warning and leaves it in shell history. For scripts, use the REDISCLI_AUTH environment variable.

Disable or rename risky commands

On recent versions, ACL categories handle this better than renaming. The -@dangerous category in the example above removes CONFIG, FLUSHALL, KEYS, DEBUG and similar commands for that user. Keep the admin account for humans only.

Firewall rules with UFW

If remote clients are needed, allow only specific sources.

sudo ufw allow from 10.0.0.0/24 to any port 6379 proto tcp
sudo ufw status numbered

Do not run sudo ufw allow 6379. That opens the port to everyone. On AlmaLinux and other firewalld systems, the equivalent is a rich rule.

sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.0/24" port port="6379" protocol="tcp" accept'
sudo firewall-cmd --reload

Also check the cloud layer. Security groups at your provider are the first line of defense, and the host firewall is the second. Use both.

TLS for traffic that leaves the host

On a shared or untrusted network, encrypt it. Redis supports TLS natively on a separate port. A minimal block looks like this.

port 0
tls-port 6379
tls-cert-file /etc/redis/tls/redis.crt
tls-key-file /etc/redis/tls/redis.key
tls-ca-cert-file /etc/redis/tls/ca.crt
tls-auth-clients yes

Set port 0 only if every client can speak TLS. Files must be readable by the redis user, with the key at mode 600 or 640. For loopback-only setups, TLS is overhead with little gain.

Step 5: Configure Persistence

Persistence is where “cache” and “database” expectations collide. Decide deliberately.

RDB snapshots

RDB writes point-in-time dumps. It is compact and quick to restore, but you can lose everything since the last snapshot.

save 3600 1 300 100 60 10000
dir /var/lib/redis
dbfilename dump.rdb

AOF

The append-only file logs every write. It is far safer for data you care about.

appendonly yes
appendfsync everysec

everysec is the practical default. You can lose about a second of writes in a crash, and throughput stays high. always is safest but costs a lot of disk I/O. no leaves flushing to the OS.

Which to choose

  • Pure cache that can be rebuilt: disable both (save "" and appendonly no) to save I/O and avoid fork latency.
  • Session store or job queue: AOF with everysec, plus RDB for backups.
  • Primary datastore: AOF, replication, and tested restores.

One real-world observation. Background saves use fork(), and on a large dataset with heavy writes, copy-on-write can nearly double memory use briefly. Teams that size RAM to exactly the dataset get OOM kills at snapshot time. Leave headroom.

Verify persistence works.

redis-cli bgsave
redis-cli lastsave
ls -lh /var/lib/redis

Step 6: Set Memory Limits and Eviction

Without maxmemory, Redis grows until the kernel intervenes. That is a bad way to find your limit.

maxmemory 2gb
maxmemory-policy allkeys-lru

Choose the policy for the workload.

Policy Behavior Use when
noeviction Rejects writes at the limit Queues, primary data
allkeys-lru Evicts least recently used keys General cache
allkeys-lfu Evicts least frequently used keys Skewed hot-key traffic
volatile-lru Evicts only keys with a TTL Mixed cache and persistent data
volatile-ttl Evicts shortest TTL first Short-lived entries

A rule of thumb: leave 25 to 40% of RAM outside maxmemory for fork overhead, client buffers, replication backlog and the OS page cache. On an 8 GB box, 5 to 6 GB is a sensible ceiling.

Watch real usage.

redis-cli info memory | grep -E 'used_memory_human|maxmemory_human|mem_fragmentation_ratio'

A fragmentation ratio far above 1.5 suggests wasted memory. Far below 1.0 means swapping, which is a serious problem.

Step 7: Tune the Kernel

Redis will warn in its logs if the OS is not set up well. Read those warnings. They are rarely cosmetic.

Overcommit memory

echo 'vm.overcommit_memory = 1' | sudo tee /etc/sysctl.d/99-redis.conf
sudo sysctl --system

Without this, background saves can fail with “Can’t save in background: fork: Cannot allocate memory”, even when free RAM looks fine.

Transparent Huge Pages

THP causes latency spikes and bloated memory during forks. Check it.

cat /sys/kernel/mm/transparent_hugepage/enabled

To disable at runtime:

echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled

Persisting this needs a systemd unit or a kernel boot parameter (transparent_hugepage=never). Check your distribution’s current default before changing it, since behavior varies.

Connection backlog

echo 'net.core.somaxconn = 1024' | sudo tee -a /etc/sysctl.d/99-redis.conf
sudo sysctl --system

Match it with tcp-backlog 511 or higher in redis.conf.

Swap

Do not disable swap entirely on every host, but keep vm.swappiness low (such as 1 to 10). A Redis process swapping to disk delivers terrible latency, so alert on swap usage.

File descriptors

For many clients, raise LimitNOFILE using a systemd override.

sudo systemctl edit redis-server
[Service]
LimitNOFILE=65535

Then set maxclients 10000 or an appropriate number in redis.conf and restart.

Step 8: Performance Considerations

Redis executes commands on a single main thread, so CPU clock speed and low latency matter more than core count. Newer versions use I/O threads for network handling, and they can help at high throughput.

io-threads 4

Enable that only after measuring. On small VMs it often does nothing useful.

Benchmark before and after any change.

redis-benchmark -q -n 100000 -c 50 -P 16
redis-cli --latency
redis-cli --latency-history -i 5

Disk matters when persistence is on. AOF fsync and RDB writes benefit from NVMe or at least SSD storage. Check I/O with iostat -x 1 from the sysstat package, or iotop. Keep the data directory off a noisy shared volume.

For network, keep Redis in the same availability zone as clients. A cross-region round trip of 30 ms kills any cache benefit. Use pipelining and connection pools in the application, and avoid commands like KEYS * in production. Use SCAN instead.

Find slow commands.

redis-cli slowlog get 10
redis-cli config get slowlog-log-slower-than

Large keys cause trouble too.

redis-cli --bigkeys
redis-cli --memkeys

Real-World Use Cases and Configs

Web cache (WordPress, Laravel, Django). Disable persistence, set maxmemory and allkeys-lru, and bind to loopback. For WordPress, a Redis object cache plugin points at 127.0.0.1:6379. Page generation times drop sharply on database-heavy sites, though results depend on the theme and query load.

Session storage. Use AOF everysec and a TTL on every session key. Losing sessions logs users out, which is annoying but survivable.

Job queues. Use noeviction, AOF, and replication. Silent eviction of queue entries is data loss.

Rate limiting and counters. Small memory footprint, atomic INCR with EXPIRE. Redis shines here.

Traffic spikes. Pre-size maxclients and file limits, and watch connected_clients, rejected_connections and evicted_keys in INFO. A sudden rise in evictions means the working set outgrew memory.

Replication and High Availability

A single instance is a single point of failure. For a basic replica, on the replica’s config:

replicaof 10.0.0.5 6379
masterauth PRIMARY_PASSWORD
masteruser replicator
replica-read-only yes

Check status with redis-cli info replication. For automatic failover, run Redis Sentinel on three nodes, or use Redis Cluster when you need sharding. Do not run two Sentinels and call it HA. Quorum needs an odd number of voters.

Backups

Copy RDB or AOF files on a schedule, and ship them off-host.

redis-cli bgsave
sudo cp /var/lib/redis/dump.rdb /backup/redis-$(date +%F).rdb

Trigger the save and wait for rdb_bgsave_in_progress:0 in INFO persistence before copying. A backup you have never restored is a hope, not a backup. Test restores on a scratch machine quarterly.

Monitoring

Useful commands for daily operations:

  • redis-cli info for the full state.
  • redis-cli monitor for a live command stream (heavy, so use briefly and never on busy production).
  • redis-cli client list to find connection hogs.
  • htop, vmstat 1, ss -s for host context.

For ongoing visibility, redis_exporter with Prometheus and Grafana is the common stack. Alert on memory above 85% of maxmemory, rising evictions, replication lag, and rdb_last_bgsave_status not being ok.

Troubleshooting Common Errors

Service fails to start after editing config

sudo journalctl -u redis-server -xe
redis-server /etc/redis/redis.conf --test-memory 1

Read the exact line number in the error. Typical culprits are typos, a bind address that does not exist on the host, or mixing user lines with aclfile.

“Could not connect to Redis at 127.0.0.1:6379: Connection refused”

The service is down, or listening elsewhere. Check systemctl status, ss -tlnp | grep 6379, and the port and bind directives.

“NOAUTH Authentication required”

You set a password and the client did not send one. Use redis-cli -a or REDISCLI_AUTH, and fix the application’s connection string.

“DENIED Redis is running in protected mode”

A remote client reached a server with no password and a non-loopback bind. The right fix is authentication and a firewall. Disabling protected mode alone is the wrong fix.

“MISCONF Redis is configured to save RDB snapshots, but it’s currently unable to persist”

Usually a permissions or disk-full problem, or overcommit. Check:

df -h /var/lib/redis
ls -ld /var/lib/redis
sudo journalctl -u redis-server | grep -i -E 'save|fork'

Confirm vm.overcommit_memory=1, and ensure the redis user owns the data directory.

“OOM command not allowed when used memory > ‘maxmemory'”

The limit was reached under noeviction. Raise maxmemory, add TTLs, switch to an eviction policy if the data is cache, or reduce key size.

Process killed by the kernel

Look for it.

sudo dmesg -T | grep -i -E 'killed process|out of memory'

Lower maxmemory, add RAM, or reduce save frequency.

Systemd unit fails with namespace or permission errors

The Debian-packaged unit uses hardening options such as ProtectSystem and restricted write paths. If you move dir to a custom location, the unit may block writes. Add the path through an override.

[Service]
ReadWritePaths=/data/redis

Then run sudo systemctl daemon-reload and restart.

High latency spikes

Check THP, swap, slow commands, big keys, and fork time with redis-cli info stats | grep latest_fork_usec. Also check noisy neighbors on shared VMs.

r00t
r00t is a Server System Administrator with more than 7 years of experience in server administration, operating systems, and programming. They have a strong track record of managing, securing, and optimizing Linux-based infrastructure (Ubuntu, Debian, CentOS/AlmaLinux) as well as Windows Server, across on-premises, VPS, and cloud environments. Their expertise covers configuring and maintaining web servers (Nginx, Apache) and databases (MySQL/MariaDB, PostgreSQL). It also includes virtualization and containers (Proxmox, Docker), networking, firewalls, and security hardening. They are experienced in monitoring, backup and disaster recovery, and troubleshooting to keep services available and performing well. Skilled in Bash, Python, and PHP, they automate routine tasks, build maintenance scripts, and manage deployments, which makes operations more efficient and less error-prone. They are known for being meticulous, responsive during incidents, and willing to share knowledge with teams and the wider community. Outside of work, r00t enjoys experimenting with homelabs, open source software, and emerging infrastructure technologies.