How to Install Redis on Ubuntu + Configuration and Common Redis Commands
- HolyHosting

- Oct 30
- 3 min read
Developers usually look for systems that increase the speed and performance of their projects. One popular system for this is Redis, an open-source in-memory database used as a cache and message broker. It is also known as a data structure server.
What makes it unique compared to relational database systems is its ability to store high-level data types, such as maps, lists, and sets. It also offers an easy-to-use interface, atomic data manipulation, and exceptional performance.
In this tutorial, we will explain the process of installing Redis on Ubuntu 18.04, 20.04, and 22.04, as well as any configuration needed for it to work properly.

Why Redis is Useful
Redis stands out for its performance and exceptional features, making it superior to traditional databases. Some common use cases are:
Cache: Redis’s enhanced ability to persist data to disk makes it a better alternative to traditional caching solutions.
Queues: It can be used to queue background jobs.
Counters: Redis allows simple creation and implementation of counters without reading data or updating the database. Counters remain consistent.
Publish/Subscribe: Users can easily distribute data using the Pub/Sub paradigm.
How to Install Redis on Ubuntu in 4 Steps
To install and configure the Redis server on Ubuntu, you need a VPS already running Ubuntu. Once prerequisites are ready, connect via SSH and begin installation.
Step 1: Update the APT Repository
Redis is included in Ubuntu’s official package repository. However, it’s recommended to update APT frequently to get the latest version:
sudo apt-get update
Step 2: Install Redis Server
Installing Redis is as simple as running:
sudo apt install redis
Press “y” and Enter to continue.
Step 3: Verify Redis Version
After installation, check if it was successful:
redis-cli --version
The output will show the installed Redis server version.
Step 4: Start Redis Service
Check if Redis is running:
sudo systemctl status redis
Look for Active: active (running).
If Redis is not started, enable the service:
sudo systemctl enable redis
Find and Edit Redis Configuration File
The default Redis configuration file is located at /etc/redis/redis.conf. By default, Redis listens to all available connections.
To bind Redis to specific interfaces, edit the bind directive:
sudo nano /etc/redis/redis.conf
Change the line:
bind 127.0.0.1 ::1
For a specific IP:
bind 70.25.220.238
For multiple IPs, separate them with spaces:
bind 70.25.220.238 70.25.220.239
To listen on all network interfaces, comment the line:
# bind 127.0.0.1 ::1
Save the file and restart Redis to apply changes:
sudo systemctl restart redis-server
Redis Commands
Redis has multiple command groups:
String commands
List commands
Set commands
Hash commands
Sorted set commands
Pub/Sub commands
Some useful commands:
redis-server /path/redis.conf # Start Redis with a specific config
redis-cli # Run Redis CLI client
APPEND key value # Append a value to a key
BITCOUNT key [start end] # Count set bits in a string
SET key value # Set a key’s value
EXPIRE key 120 # Expire a key in 120 seconds
INCR key # Increment a key’s value
KEYS pattern # Find keys matching a pattern
DEL key # Delete a key
STRLEN key # Get key length
MSET key value [key value …] # Set multiple keys
MGET key [key …] # Get multiple keys
GETSET key value # Set new value and return old value
INCRBY key increment # Increment a key by a value
DECRBY key increment # Decrement a key by a value
Renaming Dangerous Commands (Optional)
To secure Redis, it’s common to rename or disable potentially unsafe commands, like FLUSHALL, SHUTDOWN, DEL, DEBUG, and CONFIG.
Edit the security section of /etc/redis/redis.conf and rename commands, for example:
FLUSHALL -> CANTSEE_FLUSHALL
SHUTDOWN -> CANTGUESS_SHUTDOWN
DEL -> CANTHEAR_DEL
Restart Redis to apply changes:
sudo systemctl restart redis.service
Test renamed or disabled commands via redis-cli. Disabled commands will return errors, renamed commands will work as specified.
Conclusion
We hope this guide has been helpful! 🚀 Remember, don’t hesitate to ask questions on the HolyHosting Discord or contact our support team.
Follow us on Twitter @HolyHosting to stay up to date.



















