How to Install Redis on Ubuntu 18.04 and 16.04 LTS

In this article, we are going to perform, how to install Redis on Ubuntu 18.04 and 16.04 LTS. Before we proceed further, let me give you brief idea about redis.


Redis is an open source tools, which is used as a database and acts as in-memory data structure store, cache and message broker. Message brokers are building block of message-orianted-middleware(MOM), which transfers, route, respond, invoke and interact with sender/receiver end. It supports different data structures such as string, lists, sorted sets with range queries and etc. In redis, we can configure single data base structure and replication (Master-Slave) too.


  • Ubuntu 18.04/16.04 LTS
  • 2 CPU’s, 3GB RAM
  • SSH access with sudo privileges
  • Open Firewall Port: 6379

Step 1: Install Redis on Ubuntu

Let’s install redis by using below command.

$ sudo apt-get install redis-server

Next enable Redis to start on System boot. Enter below command,

$ sudo systemctl enable redis-server.service


Synchronizing state of redis-server.service with SysV init with /lib/systemd/systemd-sysv-install...

Executing /lib/systemd/systemd-sysv-install enable redis-server

To check the status of redis service.

$ sudo systemctl status redis.service


redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2019-08-09 14:17:55 UTC; 3 days ago
Main PID: 11843 (redis-server)
Tasks: 3
Memory: 11.8M
CPU: 2min 46.628s
CGroup: /system.slice/redis-server.service
└─11843 /usr/bin/redis-server

To check redis version, enter below command

$ redis-cli -v


redis-cli 3.0.6

After confirming that redis is running. Let’s run below command.

$ redis-cli> ping

If you get the output as “PONG”. Then its working fine.

Step 2: Configure Redis

Default configuration is located in /etc/redis/redis.conf. Now we will change the configuration to access redis from remote servers, defaultly  it has access only to localhost. To enable remote access uncomment and change the bindIP as below.


1. Redis as daemon

By default redis does not run as daemon and protection mode is enabled, edit the /etc/redis/redis.conf file and change to daemonize as yes, protected-mode to yes

 daemonize yes
protected-mode yes

To take effect of above configuration, restart the redis-server.

 $ sudo systemctl restart redis.service

To check redis is listening on port 6379, use below command:

$ netstat -tulpn | grep LISTEN


tcp6       0      0 :::6379                 :::*                    LISTEN    -

2. Test Redis using CLI

$ redis-cli> ping

3. To set the value> SET <key> <value>

For example:> SET 'URL'

output:> GET 'URL' 

4.To check keys> keys *

Step 3: Secure Redis

By default redis is not secured. In the configuration file /etc/redis/redis.conf, go to SECURITY section and enable authentication

1. Enable Authentication

############ SECURITY #################
#requirepass foobared

Uncomment the above and change password from foobared to <your password> and restart redis-server.

 requirepass fosstechnix 
 $ sudo systemctl restart redis.service

Now let’s test the new configuration. Open redis-cli

 $ redis-cli PING


(error) NOAUTH Authentication required.

Now use AUTH and provide your password.> AUTH <your password>> AUTH fosstechnix

If authentication is successful the output will be OK.

Step 4: Start, Restart, Stop Redis Server

Use below commands to start,restart and stop redis server using command line,

$ sudo systemctl start redis.server

$ sudo systemctl restart redis.server

$ sudo systemctl stop redis.server

To learn more about Redis. Please refer official documentation.


In this article, we have installed redis server on Ubuntu 18.04/16.04 LTS, configured bind-ip and daemonized redis. To protect our data from external users we enabled protection-mode. We created keys, secured the data by setting AUTH and mentioned commands to start,restart and stop redis server using command line.


Related Articles

How to Install Redis on CentOS 7


Sivasai Sagar

I am working as DevOps Engineer and having 5 years of Experience. Likes to share knowledge.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap