Installing Redis from source on WSL

I wanted to start playing around with Redis and decided to try and get it installed locally on my machine. I have an Azure account but even the lowest tier of their Redis offering was more than I wanted to pay, estimated at about $16/month.

I already had an installation of Windows Subsystem for Linux installed and I am running Ubuntu 18.04 Bionic distribution. This first thing I did was navigate to https://redis.io/topics/quickstart to see what their instructions said.

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

I tried running these steps verbatim and ran into a few issues

this first failed because make was not installed. So we do the following:

        $ sudo apt update
        $ sudo apt install make
    

Once apt finished installing everything we try running the make command again, and we now run into this error:

        make[3]: cc: Command not found
    

So we need to install more debian packages:

        sudo apt install build-essential
    

which will install the required compliers for building the source.

Running the make command again we hit another snag:

        In file included from adlist.c:34:0:
        zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory
    

So the default configuration on linux is to use jemalloc for memory allocation. Thanks to this Stack Overflow post, you can change the memory allocator which redis uses by supplying an argument to make. make MALLOC=libc. This compilation worked for me, however I wanted to see what else I needed to do to get the standard configuration to work.

I learned from this blog post that there are dependencies which need to be compiled first before redis can be compiled. These can be built by running the following commands.

        $ cd deps
        $ make hiredis lua jemalloc linenoise
    

Once those dependencies finish compiling, you can go back to the main /redis-stable folder and run the make command again

        $ cd ..
        $ make
    

This should finally all compile successfully, and you'll be prompted to run a make test. In doing that I found there was still one thing missing from my system.

        You need tcl 8.5 or newer in order to run the Redis test
    

was the error message that I got. So one more package install to get tcl:

        $ sudo apt-get install tcl
    

then re-running the make test command, shows that the test passed.

In summary, the order that all of this should have been done in would be something as follows

        $ sudo apt update
        $ sudo apt install make
        $ sudo apt install build-essential
        $ sudo apt-get install tcl
        $ wget http://download.redis.io/redis-stable.tar.gz
        $ tar xvzf redis-stable.tar.gz
        $ cd /redis-stable/
        $ cd /deps
        $ make hiredis lua jemalloc linenoise
        $ cd ..
        $ make