What Is Valkey?
Valkey is a fast, open-source, in-memory key-value data store. It began in March 2024 as a fork of Redis 7.2.4, after Redis changed its license, and is now developed under the Linux Foundation under a permissive BSD 3-Clause license. For most purposes it is a drop-in replacement for open-source Redis: same wire protocol, same commands, same client libraries.
If you are setting up a cache, a session store, a job queue, or a real-time leaderboard on Ubuntu, Valkey is the safe default choice in 2026. Ubuntu 24.04 ships it in its official repositories, the systemd service works out of the box, and every Redis tutorial you have ever read applies almost verbatim. This guide installs Valkey 7.2 from the Ubuntu archive, secures it, tunes it, and shows you how to migrate an existing Redis server to it without downtime.
Prerequisites
- An Ubuntu 24.04 LTS server (the same steps work on 22.04, which also ships Valkey in universe).
- A user account with sudo access.
- About 10 minutes and roughly 100 MB of disk space.
- Basic familiarity with the Linux terminal and a text editor such as nano.
Step 1: Update the System and Install Valkey
Valkey lives in Ubuntu 24.04's universe repository, so no third-party APT source is needed. Update the package index first, then install the server and the command-line tools as two separate packages.
sudo apt update
sudo apt install -y valkey-server valkey-tools
The first command refreshes the list of available packages. The second installs valkey-server (the daemon) and valkey-tools (which ships valkey-cli and valkey-benchmark). The installer creates a dedicated valkey user, enables the service, and starts it automatically.
Check that the service is running:
sudo systemctl status valkey-server
You should see active (running). If it is not running, start and enable it explicitly:
sudo systemctl enable --now valkey-server
Confirm the installed version:
valkey-server --version
On Ubuntu 24.04 this reports Valkey 7.2.x. That is an older line than the current upstream release (9.x), but it is wire-compatible with Redis 7.2, receives Ubuntu security updates, and is more than enough for caching and session storage. If you need the newest features, use the official Docker image valkey/valkey or a binary tarball from download.valkey.io instead.
Step 2: Test the Server with valkey-cli
Connect to the running server with the bundled client and run a quick smoke test.
valkey-cli ping
valkey-cli set welcome "Hello from Valkey"
valkey-cli get welcome
ping should answer PONG, and the get should return "Hello from Valkey". Remove the test key:
valkey-cli del welcome
Step 3: Understand the Default Configuration
The main configuration file is /etc/valkey/valkey.conf and the data directory is /var/lib/valkey. Out of the box, Valkey is already reasonably safe on a single server: it binds to 127.0.0.1 and ::1 only, protected mode refuses connections from other machines, and RDB snapshots are enabled. Check the key settings:
sudo grep -E "^(bind|port|protected-mode|daemonize|dir|dbfilename|appendonly)" /etc/valkey/valkey.conf
This prints the current values of the settings you are most likely to change later.
Step 4: Set a Password
Valkey ships with no password by default, which is fine while it only listens on localhost, but set one anyway. It costs thirty seconds and protects you the moment anything else on the box is ever exposed. Open the configuration file:
sudo nano /etc/valkey/valkey.conf
Find the line # requirepass foobared and change it to a strong password of your own:
requirepass YourStrongPasswordHere
Save the file and restart the service so the change takes effect:
sudo systemctl restart valkey-server
From now on, every client must authenticate. Test it with the client, passing the password with the -a flag:
valkey-cli -a 'YourStrongPasswordHere' ping
You should get PONG. Without the password, valkey-cli ping now returns NOAUTH Authentication required, which is exactly what you want.
Step 5: Configure Persistence (RDB + AOF)
Valkey keeps everything in RAM, so you need to decide what happens to your data when the server restarts. There are two mechanisms, and you can use either or both:
- RDB snapshots: the server periodically writes the whole dataset to a compact binary file. Fast to load, but you can lose a few minutes of writes.
- AOF (Append Only File): every write is logged as it happens. Slower to replay after a restart, but you lose at most a second of data.
For a cache, RDB alone is fine. For a queue or anything you cannot afford to lose, enable AOF as well. In /etc/valkey/valkey.conf, find the appendonly setting and change it:
appendonly yes
Then restart Valkey:
sudo systemctl restart valkey-server
Valkey now writes both an RDB snapshot and an AOF log into /var/lib/valkey. Check the files exist with:
sudo ls -lh /var/lib/valkey
You should see dump.rdb and an appendonlydir directory. If your dataset grows large, remember that persistence files consume disk space, so keep an eye on the volume with df -h.
Step 6: Set a Memory Limit and Eviction Policy
An in-memory store with no limit will keep growing until the Linux out-of-memory killer steps in, and that usually kills the wrong process. Set a hard cap and tell Valkey what to do when it is reached. In the configuration file, find the maxmemory setting and set it to something sensible for your server, for example 1 GB on a 4 GB machine:
maxmemory 1gb
maxmemory-policy allkeys-lru
The allkeys-lru policy evicts the least recently used keys first when the limit is hit, which is the correct behaviour for a cache. For a session store you may prefer volatile-lru, which only evicts keys that have an expiry set.
sudo systemctl restart valkey-server
Verify the limit is active:
valkey-cli -a 'YourStrongPasswordHere' info memory | grep -E "maxmemory|maxmemory_policy"
You should see maxmemory:1073741824 and maxmemory_policy:allkeys-lru.
Step 7: Apply the Two Linux Kernel Tweaks
Valkey logs two warnings on a stock Ubuntu install, and both are worth fixing: memory overcommit (Linux must allow overcommit or snapshot forks can fail) and transparent huge pages (which cause latency spikes). Apply both:
echo 'vm.overcommit_memory = 1' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
The first two commands set vm.overcommit_memory to 1 permanently and apply it immediately. The third disables transparent huge pages for the current boot; to make it survive a reboot, add transparent_hugepage=never to your kernel boot parameters. Restart Valkey and check the log is clean:
sudo systemctl restart valkey-server
sudo journalctl -u valkey-server --since "5 minutes ago" | grep -i warning
No output means no warnings.
Step 8: Lock Down Network Access with UFW
Valkey listens on port 6379. It should never be reachable from the internet. If you only use Valkey from the same machine, leave the firewall closed and do nothing. If your application runs on a different server, allow only that server's IP address:
sudo ufw allow from 203.0.113.10 to any port 6379 proto tcp
sudo ufw status
Replace 203.0.113.10 with your application server's real IP. Never run ufw allow 6379 without a source restriction: an exposed Valkey instance with no password is compromised within minutes by automated scanners.
Step 9: Migrate from Redis to Valkey
Valkey is a fork of Redis 7.2.4, so migration is straightforward for open-source Redis up to version 7.2. There are two reliable approaches.
Option A: In-place swap (same server, brief downtime)
If your Redis version is 7.2 or older, its RDB and AOF files are directly readable by Valkey. Stop Redis, install Valkey, and start it:
sudo systemctl stop redis-server
sudo apt install -y valkey-server valkey-tools
sudo systemctl start valkey-server
Valkey loads the existing data files on startup. Verify your keys survived:
valkey-cli dbsize
valkey-cli info keyspace
If you used Redis compatibility symlinks before, install the valkey-redis-compat package, which provides redis-cli and redis-server names pointing at Valkey:
sudo apt install -y valkey-redis-compat
Option B: Replication cutover (no downtime)
For a live service, run Valkey as a replica of your Redis primary, let it catch up, then promote it. On the new Valkey server, point it at the Redis primary:
valkey-cli replicaof 203.0.113.20 6379
Replace the IP with your Redis server's address. Watch replication catch up:
valkey-cli info replication
When master_link_status:up and the replication offset stops growing, stop writes to the old primary, promote the replica, and point your application at Valkey:
valkey-cli replicaof no one
That command detaches the replica and makes it a standalone primary. Update your application's connection details and confirm traffic is flowing before removing the old Redis server.
One hard limit: Valkey cannot read data files from Redis 7.4 or newer, because the file format changed after the fork. If you run Redis 7.4+, use the replication cutover above, or export and re-import your data with a migration tool, rather than copying data files.
Verify It Worked
Run through this checklist on the finished server:
sudo systemctl is-active valkey-server
valkey-cli -a 'YourStrongPasswordHere' ping
valkey-cli -a 'YourStrongPasswordHere' info server | grep valkey_version
valkey-cli -a 'YourStrongPasswordHere' set verify test && valkey-cli -a 'YourStrongPasswordHere' get verify
valkey-cli -a 'YourStrongPasswordHere' info memory | grep used_memory_human
Expected results: an active service, PONG, version 7.2.x, and test returned. As a final check, benchmark the server:
valkey-benchmark -a 'YourStrongPasswordHere' -q -n 100000
On a modest VPS, expect tens of thousands of requests per second for simple SET and GET operations. Delete the test key when you are done:
valkey-cli -a 'YourStrongPasswordHere' del verify
Common Issues and Fixes
"Could not connect to Valkey at 127.0.0.1:6379: Connection refused"
The server is not running. Check the status and the logs: sudo systemctl status valkey-server followed by sudo journalctl -u valkey-server -n 50. The most common cause is a typo in valkey.conf after editing; the log will name the offending line.
"NOAUTH Authentication required"
You set a password in Step 4 but the client is not sending one. Pass it with valkey-cli -a 'YourPasswordHere', or set it in your application's connection string. If you locked yourself out entirely, stop the service, temporarily comment out the requirepass line, restart, set a new password, and re-enable it.
"MISCONF Valkey is configured to save RDB snapshots, but it is currently not able to persist on disk"
Valkey has stopped accepting writes because it cannot write a snapshot. Usually the disk is full or /var/lib/valkey has wrong permissions. Check with df -h and ls -ld /var/lib/valkey. The directory must be owned by the valkey user. Fix ownership with sudo chown -R valkey:valkey /var/lib/valkey and restart the service.
"Can't save in background: fork: Cannot allocate memory"
This is the overcommit problem from Step 7. Set vm.overcommit_memory = 1 and apply it with sudo sysctl -p, then restart Valkey. Without this fix, background saves fail whenever the dataset is large relative to free RAM.
Port 6379 already in use after migrating from Redis
Both Redis and Valkey default to port 6379, so they cannot run side by side on the same machine. Stop and disable the old Redis service before starting Valkey: sudo systemctl stop redis-server && sudo systemctl disable redis-server. If you need both running for a replication cutover, run one of them in Docker or change the port in valkey.conf.
Conclusion
You now have Valkey 7.2 running on Ubuntu 24.04 as a systemd service, protected by a password, persisting to disk, capped at a safe memory limit, tuned at the kernel level, and firewalled off from the internet. Because Valkey speaks the same protocol as Redis, your existing client libraries, code, and tutorials all keep working, and migration from open-source Redis 7.2 or older is a near-trivial swap.
If you are replacing Redis in production, use the replication cutover rather than the in-place swap, and test the failover in staging first. Valkey Cluster and Sentinel work the same way they did under Redis, so the skills transfer directly.
Need help moving a production Redis workload to Valkey, or setting up caching for a high-traffic site? XpertBees handles server setup, migration, and performance tuning. Get in touch and we will take care of it.



