aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • DevOps
  • Programming

How To Install And Configure Redis In Ubuntu

  • root
  • May 7, 2019
  • 2 minute read

Overview

  • An In-Memory data structure store
  • Can be used for caching
  • Supports strings, hashes, lists, sets, sorted sets and other data structures.

Prerequisites

  • Operating System: Ubuntu 18
  • Command Line Interface or Terminal

Installation via Tarball

Installing via tarball is recommended as it is compiled from source.

01. Open a terminal window


Partner with aster.cloud
for your next big idea.
Let us know here.



From our partners:

CITI.IO :: Business. Institutions. Society. Global Political Economy.
CYBERPOGO.COM :: For the Arts, Sciences, and Technology.
DADAHACKS.COM :: Parenting For The Rest Of Us.
ZEDISTA.COM :: Entertainment. Sports. Culture. Escape.
TAKUMAKU.COM :: For The Hearth And Home.
ASTER.CLOUD :: From The Cloud And Beyond.
LIWAIWAI.COM :: Intelligence, Inside and Outside.
GLOBALCLOUDPLATFORMS.COM :: For The World's Computing Needs.
FIREGULAMAN.COM :: For The Fire In The Belly Of The Coder.
ASTERCASTER.COM :: Supra Astra. Beyond The Stars.
BARTDAY.COM :: Prosperity For Everyone.

 

02. Install build-essential, which will be used for building redis from source

$ sudo apt update
$ sudo apt install -y build-essential

 

Install also tcl.

$ sudo apt-get install -y tcl

 

03. Download the stable version of redis

$ wget http://download.redis.io/redis-stable.tar.gz

 

04. Unpack and build redis

$ tar xvzf redis-stable.tar.gz
$ cd redis-stable
$ sudo make

Wait until the make command finish, this might take some time.

 

Then run <strong>make install</strong>

$ sudo make install

 

05. As hinted by redis, it is a good idea to run the make test command.


$ sudo make test

This will also take some time.

06. Create the directories.


$ sudo mkdir /etc/redis

$ sudo mkdir /var/lib/redis

$ sudo mkdir /var/log/redis

 

07. Copy the template configuration file you’ll find in the root directory of the Redis distribution into /etc/redis/

$ sudo cp redis.conf /etc/redis/redis.conf

 

08. Edit the redis configuration file and apply the following.

daemonize yes
pidfile /var/run/redis-server.pid
logfile /var/log/redis/redis-server.log
dir /var/lib/redis

 

$ sudo nano /etc/redis/redis.conf

 

Update the following

...

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

...

# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# When the server runs non daemonized, no pid file is created if none is
# specified in the configuration. When the server is daemonized, the pid file
# is used even if not specified, defaulting to "/var/run/redis.pid".
#
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
pidfile /var/run/redis-server.pid

...

# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile /var/log/redis/redis-server.log

...

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis

 

Read More  DevOps For Tech Companies And Startups: Learn From Over 32,000 Professionals On How To Drive Success With Google Cloud’s DORA Research

09. Copy the init script that you’ll find in the Redis distribution under the utils directory into /etc/init.d


$ sudo cp utils/redis_init_script /etc/init.d/redis-server

 

10. Edit the init script and apply the following.

If you changed the port in /etc/redis/redis.conf to a port other than 6379. Update the init script by setting the REDISPORT value to the same port you have set in redis configuration.


$ sudo nano /etc/init.d/redis-server

 

Update the config as follows.  This setup is for running a single instance of redis, and adding a custom restart command, which just calls the stop and start as a convenience method.

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

### BEGIN INIT INFO
# Provides:     redis-server
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Redis data structure server
# Description:          Redis data structure server. See https://redis.io
### END INIT INFO

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis-server.pid
CONF="/etc/redis/redis.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    status)
        PID=$(cat $PIDFILE)
        if [ ! -x /proc/${PID} ]
        then
            echo 'Redis is not running'
        else
            echo "Redis is running ($PID)"
        fi
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

 

Read More  The 2-Minute Test For Kubernetes Pod Security

11. Add the new Redis init script to all the default runlevels.


$ sudo update-rc.d redis-server defaults

 

 

12. Configure redis server to start on system boot


$ sudo update-rc.d redis-server enable

 

 

13. Restart the server redis-server


$ sudo service redis-server restart

 

14. Test Redis by running the following command. It should return a PONG.


$ redis-cli PING

 

15. Exit from the redis-cli


$ exit

 

16. Test Redis functionality by performing simple operations. Access the redis CLI


$ redis-cli

 

17. Add new key-value pairs. An OK message should be returned.

 
127.0.0.1:6379> set pi 3.14159

 

18. Retrieve the value.

 
127.0.0.1:6379> get pi 

 

 

Installation by Package Manager

If via Package Manager, the version of Redis may be outdated.

01. In the command line

$ sudo apt update
$ sudo apt install -y redis-server

 

02. Test Redis by running the following command. It should return a PONG.

$ redis-cli PING


For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!

Our humans need coffee too! Your support is highly appreciated, thank you!

root

Related Topics
  • devops
  • How To
  • Installation
  • Redis
  • Ubuntu
You May Also Like
View Post
  • DevOps
  • Engineering
  • Platforms

How To Fail At Platform Engineering

  • March 11, 2024
View Post
  • Computing
  • DevOps
  • Platforms

The IBM Approach To Reliable Quantum Computing

  • November 28, 2023
DevOps artifact management
View Post
  • Design
  • DevOps
  • Engineering

10 Awesome Benefits Of Artifact Management And Why You Need It

  • August 2, 2023
Automation | Gears
View Post
  • Automation
  • DevOps
  • Engineering

Automating CI/CD With GitHub Actions

  • June 13, 2023
View Post
  • Architecture
  • Data
  • Engineering
  • People
  • Programming
  • Software Engineering
  • Technology
  • Work & Jobs

Predictions: Top 25 Careers Likely In High Demand In The Future

  • June 6, 2023
View Post
  • DevOps
  • People

What’s The Future Of DevOps? You Tell Us. Take The 2023 Accelerate State Of DevOps Survey

  • June 2, 2023
View Post
  • Programming
  • Software Engineering
  • Technology

Build a Python App to Alert You When Asteroids Are Close to Earth

  • May 22, 2023
View Post
  • Programming

Illuminating Interactions: Visual State In Jetpack Compose

  • May 20, 2023

Stay Connected!
LATEST
  • What is PC as a service (PCaaS)?
    • June 12, 2025
  • 2
    Apple services deliver powerful features and intelligent updates to users this autumn
    • June 11, 2025
  • By the numbers: Use AI to fill the IT skills gap
    • June 11, 2025
  • 4
    Crayon targets mid-market gains with expanded Google Cloud partnership
    • June 10, 2025
  • Apple-WWDC25-Apple-Intelligence-hero-250609 5
    Apple Intelligence gets even more powerful with new capabilities across Apple devices
    • June 9, 2025
  • Apple-WWDC25-Liquid-Glass-hero-250609_big.jpg.large_2x 6
    Apple introduces a delightful and elegant new software design
    • June 9, 2025
  • Robot giving light bulb to businessman. Man sitting with laptop on money coins flat vector illustration. Finance, help of artificial intelligence concept for banner, website design or landing web page 7
    FinOps X 2025: IT cost management evolves for AI, cloud
    • June 9, 2025
  • 8
    AI security and compliance concerns are driving a private cloud boom
    • June 9, 2025
  • 9
    Apple supercharges its tools and technologies for developers to foster creativity, innovation, and design
    • June 9, 2025
  • 10
    It’s time to stop debating whether AI is genuinely intelligent and focus on making it work for society
    • June 8, 2025
about
Hello World!

We are aster.cloud. We’re created by programmers for programmers.

Our site aims to provide guides, programming tips, reviews, and interesting materials for tech people and those who want to learn in general.

We would like to hear from you.

If you have any feedback, enquiries, or sponsorship request, kindly reach out to us at:

[email protected]
Most Popular
  • person-working-html-computer 1
    8 benefits of AI as a service
    • June 6, 2025
  • 2
    Cloud breaches are surging, but enterprises aren’t quick enough to react
    • June 6, 2025
  • 3
    Where is the cloud headed?
    • June 6, 2025
  • cookies-food-photographer-jennifer-pallian-OfdDiqx8Cz8-unsplash 4
    What is a cookie?
    • June 6, 2025
  • 5
    Enterprises are keen on cloud repatriation – but not for all workloads
    • June 4, 2025
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.