General

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

General·March 22, 2026·27 min read

Developers often look for systems that increase the speed and performance of their projects. A popular system for this is Redis, an in-memory, open-source 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 the 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 to get it working properly.

What Makes Redis Useful?

Redis stands out for its exceptional performance and features, making it a superior system compared to traditional databases. Some popular use cases are:

- Cache: Redis's enhanced ability to persist data on disk makes it a superior alternative to traditional caching solutions.

- Queues: The system can be used to queue background jobs.

- Counters: Redis allows for easy creation and implementation of counters without the need to read data or update the database. Counters in Redis will remain consistent.

- Publish and 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 will need to have a virtual private server (VPS) already running with the Ubuntu operating system installed. With all the prerequisites ready, connect via SSH and begin the installation.

Step 1: Update the APT Repository

Redis is already included in the official Ubuntu package repository. However, we recommend frequently updating the APT repository to get the most recent version possible.

```bash

sudo apt-get update

```

Step 2: Install the Redis Server on Ubuntu

Installing Redis is as simple as using the following command with sudo privileges:

```bash

sudo apt install redis

```

Press "y" and then Enter to continue.

Step 3: Verify the Redis Version

Once Redis is installed, you can verify if the installation was successful using this command:

```bash

redis-cli --version

```

The output will show the version of the Redis server installed on your machine.

Step 4: Start the Redis Service

Once the installation is complete, we recommend verifying if the Redis instance is running. To test connectivity, you can use the following command:

```bash

sudo systemctl status redis

```

In the output, look for the line "Active: active (running)".

```bash

# Screenshot showing the Redis server status on an Ubuntu system.

```

If Redis has not started and the status is inactive, you can enable the Redis client by entering the following command:

```bash

sudo systemctl enable redis

```

How to Find and Edit the Redis Configuration File on Ubuntu

The default Redis configuration file is located in the /etc/redis/redis.conf directory. The default configuration makes the Redis server listen to all available connections.

You can make it listen to the interfaces of your choice using the bind configuration directive, followed by one or more IP addresses.

To tell the Redis server to listen to a specific IP, you need to edit the /etc/redis/redis.conf file. Open it with your preferred editor; in this case, we are using nano.

```bash

sudo nano /etc/redis/redis.conf

```

Locate the line "bind 127.0.0.1 ::1".

Change the IP address by entering the values of the connections you want the Redis server to listen to. Here is an example:

```bash

bind 70.25.220.238

```

To add multiple IP addresses, simply separate them with a space, like this:

```bash

bind 70.25.220.238 70.25.220.239

```

Here you should enter the IP addresses of your network.

However, if you want the server to listen on all network interfaces, you can completely comment out the bind line:

```bash

# bind 127.0.0.1 ::1

```

Once you have finished making changes, save and close the file. Then, restart the

Redis service to apply the changes:

```bash

sudo systemctl restart redis-server

```

Using Redis Commands

There are several groups of commands in Redis, which include:

- String commands

- List commands

- Set commands

- Hash commands

- Sorted set commands

- Pub/Sub commands

Here we list some of the commands used in the Redis prompt:

- redis-server /path/redis.conf: This Redis configuration command starts Redis with a specific configuration file.

- redis-cli: A command to run the Redis CLI client.

- APPEND key value: Appends a value to a key.

- BITCOUNT key [start end]: Sets the number of bits set in a string.

- SET key value: Sets a value to a key.

- EXPIRE key 120: Expires a key in 120 seconds.

- INCR key: Increments the value in a key.

- KEYS pattern: Finds all keys matching a specific pattern.

- DEL key: Deletes a key.

- STRLEN key: Gets the length of a key.

- MSET key value [key value ...]: Sets multiple keys and values.

- MGET key [key ...]: Gets values of multiple keys.

- GETSET key value: Sets a new value returning the old value.

- INCRBY key increment: Increases the count of a key.

- DECRBY key increment: Decreases the count of a key.

Renaming Dangerous Commands (Optional)

A common practice to secure Redis is to rename or disable potentially unsafe commands. These commands are dangerous because any unauthorized user can use them to manipulate or even destroy all database data.

Keep in mind that this process is completely optional and you can decide whether to rename, disable, or leave the command active. To get started, open the /etc/redis/redis.conf file with your preferred editor. We will use nano in this example:

```bash

sudo nano /etc/redis/redis.conf

```

Then, find the SECURITY section, where you can rename or disable a command. In our example, we are renaming the FLUSHALL, SHUTDOWN, DEL commands to CANTSEE_FLUSHALL, CANTGUESS_SHUTDOWN, CANTHEAR_DEL.

We are also completely disabling the DEBUG and CONFIG commands:

```bash

# redis.conf file SECURITY section. FLUSHALL, SHUTDOWN, and DEL commands are the ones to be renamed

```

Other potentially unsafe commands include RENAME, SAVE, SREM, FLUSHDB, PEXPIRE, and BGSAVE.

To test everything, restart the Redis service:

```bash

sudo systemctl restart redis.service

```

Then, log in to the Redis command line client:

```bash

redis-cli

```

To test a disabled command, simply try using it. For example, testing the DEBUG command should look like this:

```bash

# Redis CLI tool showing the DEBUG command. It gives an error because the command was disabled

```

An error will be displayed because the DEBUG command is completely disabled. Next, test the renamed command. In our case, it is FLUSHALL.

```bash

# Redis client showing FLUSHALL command. It was renamed to CANTSEE_FLUSHALL

```

As you can see, the FLUSHALL command does not work, while our renamed CANTSEE_FLUSHALL works perfectly.

More About Databases on Ubuntu

Check out our article to learn more about how to install PostgreSQL on Ubuntu for database management.

Conclusion

The Redis database server is one of the most popular alternatives to relational databases like MySQL. With Redis, users can expect high performance and speed, especially for high-traffic websites.

In this tutorial, we have covered the main aspects of Redis and why it is so valuable.

We have also reviewed the installation process on Ubuntu 18.04, 20.04, and 22.04 systems.

Finally, we have shown some useful Redis commands and how to secure Redis by renaming unsafe commands.

We hope you found this tutorial useful. If you have any questions or comments, leave them in the comments section below.

Still have questions?

Come chat with us and we will get back to you as soon as possible!

Contact Support