How to Install Redis on Ubuntu Server 22.04

Redis is an in-memory key-value store known for its flexibility, performance, and wide language support. This tutorial demonstrates how to install, configure, and secure Redis on an Ubuntu 22.04 server using EcoStack Cloud.

redis ubuntu database
Medium
VPS
2
vCPU
8 GB
Memory
80 GB
NVMe Disk
4096 GB
Traffic
20.90
/month
* Up to 4 vCPU, 24GB RAM, 240GB NVMe Disk Space and 1Gbit/s Network Speed
## Testing Redis As with any newly-installed software, it’s a good idea to ensure that Redis is functioning as expected before making any further changes to its configuration. We will go over a handful of ways to check that Redis is working correctly in this step. Start by checking that the Redis service is running: ```sh sudo systemctl status redis ``` If it is running without any errors, this command will produce output similar to the following: ```plaintext ● redis-server.service - Advanced key-value store Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2022-04-20 20:40:52 UTC; 4s ago Docs: http://redis.io/documentation, man:redis-server(1) Main PID: 2899 (redis-server) Status: "Ready to accept connections" Tasks: 5 (limit: 2327) Memory: 2.5M CPU: 65ms CGroup: /system.slice/redis-server.service └─2899 "/usr/bin/redis-server 127.0.0.1:6379 . . . ``` This output indicates that Redis is running and is already enabled, meaning that it is set to start up every time the server boots. > **Note:** This setting is desirable for many common use cases of Redis. If, however, you prefer to start up Redis manually every time your server boots, you can configure this with the following command: ```sh sudo systemctl disable redis ``` To test that Redis is functioning correctly, connect to the server using `redis-cli`, Redis’s command-line client: ```sh redis-cli ``` In the prompt that follows, test connectivity with the `ping` command: ```sh ping ``` ```plaintext PONG ``` This output confirms that the server connection is still alive. Next, check that you’re able to set keys by running: ```sh set test "It's working!" ``` ```plaintext OK ``` Retrieve the value by typing: ```sh get test ``` Assuming everything is working, you will be able to retrieve the value you stored: ```plaintext "It's working!" ``` After confirming that you can fetch the value, exit the Redis prompt to get back to the shell: ```sh exit ``` As a final test, we will check whether Redis is able to persist data even after it’s been stopped or restarted. To do this, first restart the Redis instance: ```sh sudo systemctl restart redis ``` Then connect with the command-line client again: ```sh redis-cli ``` And confirm that your test value is still available ```sh get test ``` The value of your key should still be accessible: ```plaintext "It's working!" ``` Exit out into the shell again when you are finished: ```sh exit ``` With that, your Redis installation is fully operational and ready for you to use. However, some of its default configuration settings are insecure and provide malicious actors with opportunities to attack and gain access to your server and its data. The remaining steps in this tutorial cover methods for mitigating these vulnerabilities, as prescribed by the official Redis website. Although these steps are optional and Redis will still function if you choose not to follow them, it is strongly recommended that you complete them in order to harden your system’s security. ---


Created with ❤ at Estonia
EcoStack Technology OÜ