Cyberithub

How to Install Redis on Ubuntu 18.04

Advertisements

In this tutorial, I will take you through the steps to install redis on Ubuntu 18.04. As defined in Redis Documentation Redis is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. It supports various abstract data structures like string, map, sets, lists, sorted sets, Hashes etc.

Redis is unimaginably fast as it is written in C Language which deals with memory addresses directly and it is basically a NoSQL Database.

How to Install Redis on Ubuntu 18.04 2

How to Install Redis on Ubuntu 18.04

Also Read: How to Install and Configure an NFS Server on Ubuntu 18.04 Using 11 Easy Steps

Step 1: Prerequisites

a) You should have a running Ubuntu 18.04 Server.

b) You should have sudo or root access to run privileged commands.

c) You should have apt or apt-get utility available in your System.

 

Step 2: Update the System

Firstly you need to update your system using apt-get update command.

root@localhost:~# apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Hit:5 http://ppa.launchpad.net/ansible/ansible/ubuntu bionic InRelease
Get:6 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [81 6 kB]
Get:7 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [593 kB]
Get:8 http://security.ubuntu.com/ubuntu bionic-security/main i386 Packages [413 kB]
Get:9 http://security.ubuntu.com/ubuntu bionic-security/main amd64 DEP-11 Metada ta [38.6 kB]
Get:10 http://security.ubuntu.com/ubuntu bionic-security/main DEP-11 48x48 Icons [17.6 kB]
Get:11 http://security.ubuntu.com/ubuntu bionic-security/main DEP-11 64x64 Icons [41.5 kB]
Get:12 http://security.ubuntu.com/ubuntu bionic-security/universe i386 Packages [601 kB]
Get:13 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [626 kB]
Get:14 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [209 kB]
Get:15 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 DEP-11 M etadata [42.2 kB]
Get:16 http://security.ubuntu.com/ubuntu bionic-security/universe DEP-11 48x48 I cons [16.4 kB]
Get:17 http://security.ubuntu.com/ubuntu bionic-security/universe DEP-11 64x64 I cons [111 kB]
Get:18 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 DEP-11 Metadata [2,464 B]

..........................................................................................................................................................................

 

Step 3: Install Redis Server

Once updated, Install Redis server using apt get install redis-server command.

root@localhost:~# apt-get install redis-server -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libjemalloc1 redis-tools
Suggested packages:
ruby-redis
The following NEW packages will be installed:
libjemalloc1 redis-server redis-tools
0 upgraded, 3 newly installed, 0 to remove and 230 not upgraded.
Need to get 634 kB of archives.
After this operation, 3,012 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 libjemalloc1 amd64 3.6.0-11 [82.4 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 redis-tools amd64 5:4.0.9-1ubuntu0.2 [516 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 redis-server amd64 5:4.0.9-1ubuntu0.2 [35.4 kB]
Fetched 634 kB in 0s (1,345 kB/s)
.............................................................................................

 

Step 4: Configure Redis Service

After successfully installing the redis service you need to find the supervised directive in /etc/redis/redis.conf and change its value from "no" to "systemd" as shown below. Then save and exit.

root@localhost:~# cat /etc/redis/redis.conf | grep -i supervised
# 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
supervised systemd

 

Step 5: Restart Redis Service

Once configuration is done, you need to restart the Redis service for the changes to get reflected. It is also worth noting that by default redis service will run on redis port 6379 as can be seen below.

root@localhost:~# systemctl restart redis

Check the status of Redis Service after doing restart.

root@localhost:~# systemctl status redis
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-12-10 02:58:43 IST; 9s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 3397 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 3400 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
Main PID: 3402 (redis-server)
Tasks: 4 (limit: 2333)
CGroup: /system.slice/redis-server.service
└─3402 /usr/bin/redis-server 127.0.0.1:6379

 

Step 6: Test Redis Server

Once service is restarted, we can test Redis Server Connection by setting the key value pair. Here we will set the value of key hello to cyberithub. So when you try to access the value of hello using get, you will see the value cyberithub in the output. This is the most simplistic way to test Redis Server Connection.

127.0.0.1:6379> set hello cyberithub
OK
127.0.0.1:6379> get hello
"cyberithub"

Leave a Comment