Back to Jots

Install any version of Redis in Ubuntu

Sometimes, you may want to install the latest version of Redis in Ubuntu or your may want to install a version of Redis that is not available in the Ubuntu’s repositories. Here’s how you can install any version of Redis in Ubuntu. Download the source code of the Redis version you wish to install and compile it

export REDIS_VERSION="2.4.2"
mkdir -p ~/builds
cd ~/builds
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/redis/redis-${REDIS_VERSION}.tar.gz
tar xvzf redis-${REDIS_VERSION}.tar.gz
cd redis-${REDIS_VERSION}
make

Ensure the compiled redis binary works correctly

sudo apt-get update &&apt-get install -y tcl8.5
make test

Install redis

sudo make install

Create the redis group and the redis user and add the redis user to the redis group

addgroup --system redis
adduser --system --disabled-login --ingroup redis --home /var/lib/redis --gecos "redis server" --shell /bin/false redis
usermod -a -G redis rails
sudo usermod -a -G redis $USERNAME

Create a directory for redis to store its dump file. Since we use Capistrano to deploy our apps, I’ve chosen to use this directory

mkdir -p /home/$USERNAME/apps/myapp/shared/redis/
sudo chown redis:redis /home/$USERNAME/apps/myapp/shared/redis/

Create the log directory

sudo mkdir -p /var/log/redis/
sudo chown redis:redis /var/log/redis/

Create an init script to start/stop redis

cd /etc/init.d/
sudo wget https://gist.githubusercontent.com/nisanth074/e83056ea808cdca7e0ac3e483ceeac65/raw/2cbe31ce84c009303dc899748bcd310b25331c9c/redis-server

Create the redis config file

sudo mkdir -p /etc/redis
sudo cp ~/builds/redis-${REDIS_VERSION}/redis.conf /etc/redis/

and configure redis

sudo vim /etc/redis/redis.conf

Redis by default listens for incoming connections on all network interfaces. You may want to configure Redis to only listen on a specific ip address

bind 1.2.3.4

Configure redis to save its dump in a different location if you’d like to

dir /home/your_username/apps/myapp/shared/redis/

Start redis

sudo /etc/init.d/redis-server start

Configure Ubuntu to automatically start Redis at boot time

sudo update-rc.d redis-server defaults

Built with Hugo & Notion. Source code is available at GitHub.