Setting up Redis on macOS Sierra
Happy days are here! I got a brand spanking new development laptop. I replaced my 2013 Retina MacBook Pro, and, despite mixed reviews, I went to a MacBook Pro 15" with the touch bar. The novelty of the touch bar hasn’t worn of yet and, honestly, I don’t miss the function keys yet. My reason for upgrading is that my old MacBook has always been a touch flakey (even after a logic board replacement) but the random reboots and kernel panics have started to increase. I’m running more VMs these days too and the extra ram (from 8gb→16gb) is welcome.
The joy of a new machine is always tempered by the pain of getting your development environment back just right. I’ve installed Redis on quite a few machines and servers and it’s been a set it and forget it affair.
I still want that convenience, but I also want a little more flexibility. Most of the instructions/scripts floating around the web install Redis on a Mac as root. I really don’t want that — I want Redis to run as a user so if I’m logged in under a different account, it doesn’t run. Redis also doesn’t really need to be root in a development situation. Finally, the less I have to type sudo the better.
Since I’m doing some development on Redis modules, it’s also possible that I will have multiple Redis server instances running at one time. It makes sense to have a more logical and contained pattern to my directories rather than spreading everything around the file system. So, here are my steps to install Redis on a fresh macOS system.
- Download Redis. I’m installing 4.0 RC2 in this case. I followed the instructions on this page, up to the untaring bit.
- Before you
make
. It’s wise to enableDevToolsSecurity
, if you don’t then you’ll be greeted with dozens of dialog boxes to enter your password or use your finger print. You can see how to enable it on stackoverflow. - In the terminal
$ make
- Then
$ make test
Hopefully everything works and you get the victorious\o/
- Next up, let’s create the plist file for Redis
$ nano ~/Library/LaunchAgents/io.redis.redis-server.plist
Set the value to this (replacing with your own directory)
- Make a directory to hold your Redis related stuff. We’ll do it off your home directory (
$ mkdir ~/redis
). This way, we centralize a few things and making swapping out new versions in the future a breeze. - Now, let’s use symbolic links for a couple of important executables. At a later point, you can change these to a new version while retaining the old version for testing or what not.
$ ln -s /Users/YOURUSERDIRECTORY/redis-4.0-rc2/src/redis-server /Users/YOURUSERDIRECTORY/redis/redis-server
$ ln -s /Users/YOURUSERDIRECTORY/redis-4.0-rc2/src/redis-cli /Users/YOURUSERDIRECTORY/redis/redis-cli
- I want to retain the
redis.conf
as an actual file. This way I can keep the settings the same when I change versions later (although be aware that future versions may have new things in the conf file). Let’s copy the stock conf file from the install into our newly created~/redis
directory.
$ cp /Users/YOURUSERDIRECTORY/redis-4.0-rc2/redis.conf ./redis.conf
- In the
redis.conf
, I made a few changes. First, set the directory of thedump.rdb
file to our newly created~/redis
directory.
dir ./Users/YOURUSERDIRECTORY/redis/
- Next, I set a password (which really shouldn’t be optional). It’s the
requirepass
line in the conf. - Now that you’re
redis.conf
is minimally setup, load in the new plist file and start the server.
$ launchctl load ~/Library/LaunchAgents/io.redis.redis-server.plist
$ launchctl start io.redis.redis-server
- To be able to access your executables from any directory, let’s add it to path. To do this, you need to edit a file:
$ nano ~/.bash_profile
- In the file (which might be empty), add the line:
export PATH=$PATH:/Users/YOURUSERDIRECTORY/redis
- After saving the file, you can put it into action for the first time by doing:
$ . $HOME/.bash_profile
There you have it — setup instructions for Redis that are only for a single user. I wrote this for my future self as much as for anyone else, so I hope you find it useful (Kyle-in-the-future and others)!