How to Install Redis on Ubuntu 18.04 LTS

|
Last Updated:
|
|

This guide presents a simple of how to install Redis on Ubuntu 18.04 LTS. So what is Redis? Redis is a free and open-source in-memory database. It implements different key-value data structures some of them being sets, bitmaps, hashes, lists, strings, streams…Redis can function as a cache, database or message broker.

How to Install Redis on Ubuntu 18.04 LTS

To begin with, re-synchronize your system packages to the latest versions.

apt update
apt upgrade

After the package update and upgrade is done, proceed to install Redis on Ubuntu 18.04 LTS server.

Install Redis on Ubuntu 18.04 LTS

Installation of Redis on Ubuntu 18.04 is pretty simple since the package is contained on default Ubuntu repositories. Hence, use the package manager to install it as shown below;

apt install redis-server

This command installs Redis server and all the required dependencies on Ubuntu 18.04.

Configuring Redis on Ubuntu 18.04

Redis is now installed on Ubuntu 18.04. Before we can Redis as a service, there are a few configuration adjustments that we are going to make in its main configuration file, /etc/redis/redis.conf. The adjustment that we are going to make is to define systemd as the init system that will manage the Redis service. This can be achieved by changing the line supervised no to supervised systemd.

vim /etc/redis/redis.conf
...
# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
#supervised no
supervised systemd
...

Restart Redis Server

When installation completes, Redis server is set to start by default. To clear the doubt, execute the command below to check the Redis server service status.

systemctl status redis-server
 redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-01-13 16:41:41 EAT; 2min 1s ago
     Docs: http://redis.io/documentation,
           man:redis-server(1)
 Main PID: 22095 (redis-server)
    Tasks: 4 (limit: 1110)
   CGroup: /system.slice/redis-server.service
           └─22095 /usr/bin/redis-server 127.0.0.1:6379

However, since we have made some configuration changes, be sure to restart it.

systemctl restart redis-server

Redis server is also set to run on system reboot. This can be verified by running the command below;

systemctl list-unit-files --state=enabled | grep redis-server
redis-server.service                  enabled

Testing Redis Server on Ubuntu 18.04

So that we can be sure that we have installed Redis server on Ubuntu 18.04 and working fine, you can perform a few simple tests using Redis command line tool called redis-cli. Redis server by default listens on TCP port 6379 and loopback address, 127.0.0.1. As a result, redis-cli connect to Redis server via 127.0.0.1:6378.

To test the connection, we are going to perform the simple ping pong test. See below.

redis-cli 
127.0.0.1:6379> ping
PONG                 < Response from server
127.0.0.1:6379>

This can also be done using a one line command;

redis-cli -h 127.0.0.1 -p 6379 ping
PONG

These few tests have confirmed that our Redis server is working fine. However, if yo need to perform more tests, check here.

This guide has simply taken you through the simple steps of how to install Redis on Ubuntu 18.04 LTS. Thank you for reading.

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment