Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Databases

Redis or Valkey on Ubuntu: install, secure and size it

Install Redis 8 or Valkey 9 on Ubuntu 24.04 or 26.04, choose the right package and license, lock it down with ACL users, and set memory and persistence.

CloudSat teamNovember 18, 20266 min read
Small glowing cubes orbiting a bright central core along fast elliptical paths on a dark background.
On this pagePick a package

Redis keeps data in memory and answers in well under a millisecond, which is why it sits behind so many caches, session stores, rate limiters and job queues. On Ubuntu in late 2026, "install Redis" means choosing between three sources: Ubuntu's own redis-server, the packages Redis publishes itself, and Valkey, the fork run under the Linux Foundation. For everyday commands they behave the same, and client libraries talk to all three. The differences are version, license and a few features.

Pick a package

Source Version in November 2026 License
Ubuntu 24.04 redis-server 7.0.15 BSD-3-Clause
Ubuntu 26.04 redis-server 8.0.5 RSALv2, SSPLv1 or AGPLv3
Redis APT repository (redis) 8.10.x RSALv2, SSPLv1 or AGPLv3
Ubuntu 26.04 valkey-server 9.0.4 (upstream is at 9.1.3) BSD-3-Clause

Redis 7.2 and earlier are BSD-licensed. From Redis 8, you choose one of three licenses, one of them the OSI-approved AGPLv3. Redis 8 also absorbed what used to be the Redis Stack modules, and the packages Redis builds itself ship JSON documents, time series, probabilistic structures and the search and query engine alongside the core server. Valkey started in 2024 from the Redis 7.2.4 code base, stayed under the BSD license, and now ships releases on its own schedule.

A sensible default: Valkey from Ubuntu 26.04 if you want a permissive license and distribution updates, Redis from its own repository if you want Redis 8's newest data types and query engine. On CloudSat, both Redis and Valkey are also available as one-click apps.

Option A: Redis from Redis's repository

sudo apt-get install -y lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install -y redis
redis-cli ping

The service is redis-server, the configuration lives in /etc/redis/redis.conf, and redis-cli ping answers PONG. To stay on one release line, pin it with an APT preferences file, as Redis's install documentation shows.

Option B: Valkey from Ubuntu 26.04

sudo apt update
sudo apt install -y valkey-server
valkey-cli ping

The service is valkey-server, the configuration is /etc/valkey/valkey.conf, and the tools are named valkey-cli, valkey-benchmark and so on. Everything below applies to both; swap the file and command names.

Lock it down

Keep it on loopback

Both packages ship with bind 127.0.0.1 -::1 and protected-mode yes, so the server only accepts local connections. Check with sudo ss -tlnp | grep 6379. If another server must connect, add TLS and a firewall rule for that client alone. Never publish port 6379 to the internet: an open instance gets found by scanners, and a misused instance can be turned against the server itself.

Replace the default user with named ACL users

Without configuration, every local connection acts as the all-powerful default user with no password. Turn that user off and define your own in an ACL file. Point the configuration at it by adding aclfile /etc/redis/users.acl to redis.conf, then create the file:

user default off
user admin on >REPLACE_WITH_A_LONG_RANDOM_PASSWORD ~* &* +@all
user app on >REPLACE_WITH_ANOTHER_PASSWORD ~app:* &app:* +@read +@write +@connection -@dangerous

~app:* limits the application to keys starting with app:, &app:* does the same for pub/sub channels, and -@dangerous removes commands such as FLUSHALL, KEYS and CONFIG. Generate passwords with openssl rand -base64 32, then protect the file and restart:

sudo chown redis:redis /etc/redis/users.acl
sudo chmod 640 /etc/redis/users.acl
sudo systemctl restart redis-server
redis-cli --user admin --askpass ping

For Valkey, the file belongs to the valkey user and the service is valkey-server. Applications then connect with redis://app:PASSWORD@127.0.0.1:6379/0.

Decide what the server is for

A cache and a data store need opposite settings, so decide first.

Memory limit and eviction

By default there is no memory limit and the eviction policy is noeviction: when memory runs out, writes fail. For a cache, set a ceiling and let the server drop keys:

maxmemory 1gb
maxmemory-policy allkeys-lru
Policy What gets evicted Fits
noeviction Nothing; writes fail when full Queues and data you cannot lose
allkeys-lru Least recently used keys General caching
allkeys-lfu Least frequently used keys Caches with a stable set of hot keys
volatile-lru Least recently used keys that have a TTL Caches mixed with permanent keys
volatile-ttl Keys closest to expiry Short-lived data

Persistence

RDB snapshots write the whole dataset to disk periodically; upstream's default rules save after one hour with one change, five minutes with 100 changes, or one minute with 10,000, and CONFIG GET save shows what your build uses. The append-only file logs every write; with appendonly yes and the default appendfsync everysec, a crash costs at most about a second of writes. Use both for data you care about. For a pure cache, turn both off with save "" and appendonly no, and the server restarts empty and fast.

The kernel setting the log asks for

Saves fork the server process. With Linux's default overcommit behavior, that fork can fail on a busy machine, and the server logs a warning at startup. Fix it once:

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

High availability, when you need it

A single instance restarts in seconds and reloads its RDB or append-only file, which is enough for most caches. When the data matters and downtime does not fit, add a replica: set replicaof on a second server, give it the credentials of an ACL user allowed to replicate, and run Sentinel (Redis Sentinel or Valkey Sentinel) to promote the replica automatically if the primary fails. Run three Sentinel processes on separate machines so a majority can agree on what happened. The tradeoffs are the same as for any database, and the database clustering guide walks through them.

Commands worth knowing

redis-cli --user admin --askpass
INFO memory
SCAN 0 MATCH session:* COUNT 100
MEMORY USAGE session:42
TTL session:42
SLOWLOG GET 10

Use SCAN instead of KEYS on anything but an empty test server: KEYS blocks the single command thread while it walks every key. redis-cli --latency measures round trips from where you run it, and MONITOR prints every command, which is useful for a minute of debugging and costly if left running.

FAQ

Should I choose Redis or Valkey?

For caching, sessions and queues, either works and clients do not care. Choose Redis 8 if you want its built-in JSON, search and vector features. Choose Valkey for a BSD license and a project governed by a foundation. Ubuntu 26.04 packages both, so you can switch later with little effort.

Can I use Redis 8 in a commercial product?

Using it as the cache or database behind your own application is the common case, and you can pick the AGPLv3 among its three licenses. Obligations grow if you modify Redis itself and offer it to others over a network, so read the license that fits your plans, or ask someone qualified.

How much RAM should I plan for?

Your dataset, plus overhead per key, plus headroom for persistence: during a save, pages that change are copied, which can briefly raise memory use. Set maxmemory clearly below the server's RAM so the operating system and those copies always have room.

Can I run it in Docker instead?

Yes, with one caveat: publish the port on loopback with -p 127.0.0.1:6379:6379, because ports Docker publishes on all interfaces can bypass ufw.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.