Risan Bagja

Install Redis on Ubuntu

Install required packages:

$ sudo apt-get update
$ sudo apt-get install build-essential tcl

Download Redis, build it, and then install it:

$ cd /tmp
$ curl -O http://download.redis.io/redis-stable.tar.gz
$ tar xzvf redis-stable.tar.gz
$ cd redis-stable
$ make
$ make test
$ sudo make install

Create a dedicated user for Redis and prepare the storage location:

$ sudo adduser --system --group --no-create-home redis
$ sudo mkdir /var/lib/redis
$ sudo chown redis:redis /var/lib/redis
$ sudo chmod 770 /var/lib/redis

Update Redis configuration:

$ sudo mkdir /etc/redis
$ sudo cp /tmp/redis-stable/redis.conf /etc/redis
$ sudo vim /etc/redis/redis.conf
# redis.conf
supervised systemd
dir /var/lib/redis

Create systems unit file:

$ sudo vim /etc/systemd/system/redis.service
# redis.service
Description=Redis In-Memory Data Store

ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown


Start redis service:

$ sudo systemctl start redis
$ sudo systemctl status redis
$ redis-cli ping

Do some testing:

$ redis-cli
set test "It's working!"
get test

# Restart and test the get
$ sudo systemctl restart redis
$ redis-cli
get test
del test

Enable Redis to start at boot:

$ sudo systemctl enable redis