Homebrew: how to remove redis/4.0.2 and use redis@3.2 as my default redis

Viewed 9793

I started this quest with redis/3.0.3 installed, and looking to upgrade my local dev redis to version 3.2.3, which is what we're running in production. I ultimately ran brew upgrade redis, which installed redis 4.0.2, ahead of my desired version. Then I found that you can install 3.2.x with brew install redis@3.2. Also, while trying to cleanup 4.0.2, instead it cleaned up only 3.0.3.

Now I'm stuck in a situation where Homebrew won't allow me to uninstall redis/4.0.2, and views redis@3.2 as a separate Homebrew Formula.

$ brew switch redis 3.2
Error: redis does not have a version "3.2" in the Cellar.
Versions available: 4.0.2

See how in the Cellar, they're showing as separate Formulae here:

$ ls  /usr/local/Cellar/ | grep redis  
redis
redis@3.2

What is the correct "Homebrew" way to remove redis/4.0.2 and use redis@3.2 as my default redis, so that commands to redis-server and redis-cli reference 3.2 instead? I'm running Mac OS X Yosemite 10.10.5 and Homebrew 1.3.4.

$ ls -l /usr/local/bin/ | grep redis
lrwxr-xr-x  1 jsoro  wheel        41 Oct  5 12:51 redis-benchmark -> ../Cellar/redis/4.0.2/bin/redis-benchmark
lrwxr-xr-x  1 jsoro  wheel        41 Oct  5 12:51 redis-check-aof -> ../Cellar/redis/4.0.2/bin/redis-check-aof
lrwxr-xr-x  1 jsoro  wheel        41 Oct  5 12:51 redis-check-rdb -> ../Cellar/redis/4.0.2/bin/redis-check-rdb
lrwxr-xr-x  1 jsoro  wheel        35 Oct  5 12:51 redis-cli -> ../Cellar/redis/4.0.2/bin/redis-cli
lrwxr-xr-x  1 jsoro  wheel        40 Oct  5 12:51 redis-sentinel -> ../Cellar/redis/4.0.2/bin/redis-sentinel
lrwxr-xr-x  1 jsoro  wheel        38 Oct  5 12:51 redis-server -> ../Cellar/redis/4.0.2/bin/redis-server
1 Answers

The issue was trivial and could have been easier if the Brew Docs/FAQs were more clear. The Brew FAQs say that uninstalls are handled by brew cleanup <formula>, which is what caused my redis/3.0.3 to be removed. However, brew cleanup would not remove redis/4.0.2. To remove it I used brew uninstall, which I could not find in the Docs...

$ brew uninstall redis
Uninstalling /usr/local/Cellar/redis/4.0.2... (11 files, 2.7MB)

Then, to fix the remaining issue of redis@3.2 not being symlinked under /usr/local/bin/, I first tried an uninstall/re-install of redis@3.2 to see if Homebrew would take care of it...

$ ls -l /usr/local/bin/ | grep redis
$ brew uninstall redis@3.2
Uninstalling /usr/local/Cellar/redis@3.2/3.2.11... (11 files, 1.7MB)
$ brew install redis@3.2
==> Downloading http://download.redis.io/releases/redis-3.2.11.tar.gz
## TRIMMED ##
==> Summary
  /usr/local/Cellar/redis@3.2/3.2.11: 11 files, 1.7MB, built in 10 seconds

Of course, this did not create the symlinks--actually the Caveats section which I trimmed away from the output says this explicitly with suggestions. Instead of using their suggestion, I opted to create symlinks manually:

$ cd /usr/local/bin/
$ ls -l | grep redis
$
$ ln -s /usr/local/Cellar/redis\@3.2/3.2.11/bin/redis-check-aof redis-check-aof
$ ln -s /usr/local/Cellar/redis\@3.2/3.2.11/bin/redis-check-rdb redis-check-rdb
$ ln -s /usr/local/Cellar/redis\@3.2/3.2.11/bin/redis-cli redis-cli
$ ln -s /usr/local/Cellar/redis\@3.2/3.2.11/bin/redis-sentinel redis-sentinel
$ ln -s /usr/local/Cellar/redis\@3.2/3.2.11/bin/redis-server redis-server
$ ls -l | grep redis
lrwxr-xr-x  1 jsoro  wheel        54 Oct  5 14:27 redis-check-aof -> /usr/local/Cellar/redis@3.2/3.2.11/bin/redis-check-aof
lrwxr-xr-x  1 jsoro  wheel        54 Oct  5 14:27 redis-check-rdb -> /usr/local/Cellar/redis@3.2/3.2.11/bin/redis-check-rdb
lrwxr-xr-x  1 jsoro  wheel        48 Oct  5 14:27 redis-cli -> /usr/local/Cellar/redis@3.2/3.2.11/bin/redis-cli
lrwxr-xr-x  1 jsoro  wheel        53 Oct  5 14:27 redis-sentinel -> /usr/local/Cellar/redis@3.2/3.2.11/bin/redis-sentinel
lrwxr-xr-x  1 jsoro  wheel        51 Oct  5 14:26 redis-server -> /usr/local/Cellar/redis@3.2/3.2.11/bin/redis-server

The last thing to note is that since I had run the redis-server while under the redis/4.0.2 version, the dump.rdb file was no longer compatible. Running redis-server using redis 3.2.x on a 4.x dump.rdb causes the server to exit immediately.

$ redis-server
## TRIMMED ##
38504:M 05 Oct 14:29:07.234 # Server started, Redis version 3.2.11
38504:M 05 Oct 14:29:07.259 # Can't handle RDB format version 8
38504:M 05 Oct 14:29:07.260 # Fatal error loading the DB: Invalid argument. Exiting.

Unfortunately you need to rm dump.rdb, or remove/rename the dump.rdb file, in order to get redis-server to start up again.

Related