Skip to content

Instantly share code, notes, and snippets.

@czarneckid
Created December 29, 2011 21:08
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save czarneckid/1536207 to your computer and use it in GitHub Desktop.
Save czarneckid/1536207 to your computer and use it in GitHub Desktop.
Installing older or specific versions of Homebrew formulas

We first want to take a look at what versions are installed for a given formula, brew info FORMULA. Let's take a look at the versions of Redis that are installed.

@czq. ➜  Formula rvm:() git:(master) brew info redis
redis 2.4.5
http://redis.io/
/usr/local/Cellar/redis/2.4.4 (9 files, 460K)
/usr/local/Cellar/redis/2.4.5 (9 files, 460K) *
...

The * indicates the currently selected version of the formula. In this case, Redis 2.4.5.

Now we want to install Redis 2.0.4. Under the Formulas for homebrew, find the formula file, in this case redis.rb and click on the commit history for the file, https://github.com/mxcl/homebrew/commits/master/Library/Formula/redis.rb. Copy the SHA of the commit for the specific version in question, 123276d643bdfe2d0ffaffc5ed579c6d54df1f3c, which is the commit for Redis 2.0.4 support.

Change to your /usr/local/Library/Formula directory and checkout the Redis 2.0.4 SHA for the Redis formula.

git checkout 123276d643bdfe2d0ffaffc5ed579c6d54df1f3c redis.rb

Upgrade, actually downgrade in this case, Redis.

@czq. ➜  Formula rvm:() git:(master) ✗ brew upgrade redis
==> Upgrading redis
==> Downloading http://redis.googlecode.com/files/redis-2.0.4.tar.gz
######################################################################## 100.0%
Warning: Building with LLVM, but this formula is reported to not work with LLVM:

Breaks with LLVM

We are continuing anyway so if the build succeeds, please open a ticket with
the following information: 2335-10.7. So
that we can update the formula accordingly. Thanks!

If it doesn't work you can: brew install --use-gcc

==> make -C .
==> Caveats
If this is your first install, automatically load on login with:
    cp /usr/local/Cellar/redis/2.0.4/io.redis.redis-server.plist ~/Library/LaunchAgents
    launchctl load -w ~/Library/LaunchAgents/io.redis.redis-server.plist

If this is an upgrade and you already have the io.redis.redis-server.plist loaded:
    launchctl unload -w ~/Library/LaunchAgents/io.redis.redis-server.plist
    cp /usr/local/Cellar/redis/2.0.4/io.redis.redis-server.plist ~/Library/LaunchAgents
    launchctl load -w ~/Library/LaunchAgents/io.redis.redis-server.plist

  To start redis manually:
    redis-server /usr/local/etc/redis.conf

  To access the server:
    redis-cli
==> Summary
/usr/local/Cellar/redis/2.0.4: 153 files, 1.3M, built in 3 seconds

Reset the SHA for the Redis formula.

@czq. ➜  Formula rvm:() git:(master) ✗ git reset --hard HEAD
HEAD is now at b5326eb gnutls: fix detection of libtasn1

Now we can switch to Redis 2.0.4.

@czq. ➜  Formula rvm:() git:(master) brew switch redis 2.0.4
Cleaning /usr/local/Cellar/redis/2.0.4
Cleaning /usr/local/Cellar/redis/2.4.4
Cleaning /usr/local/Cellar/redis/2.4.5
6 links created for /usr/local/Cellar/redis/2.0.4
@czq. ➜  Formula rvm:() git:(master) redis-server 
[4631] 29 Dec 15:53:52 # Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf'
[4631] 29 Dec 15:53:52 * Server started, Redis version 2.0.4
[4631] 29 Dec 15:53:52 * The server is now ready to accept connections on port 6379
[4631] 29 Dec 15:53:52 - 0 clients connected (0 slaves), 1074272 bytes in use
^C

Or switch back to the latest version, 2.4.5.

@czq. ➜  Formula rvm:() git:(master) brew switch redis 2.4.5
Cleaning /usr/local/Cellar/redis/2.0.4
Cleaning /usr/local/Cellar/redis/2.4.4
Cleaning /usr/local/Cellar/redis/2.4.5
5 links created for /usr/local/Cellar/redis/2.4.5
@czq. ➜  Formula rvm:() git:(master) redis-server           
[4660] 29 Dec 15:54:02 # Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf'
[4660] 29 Dec 15:54:02 * Server started, Redis version 2.4.5
[4660] 29 Dec 15:54:02 * The server is now ready to accept connections on port 6379
[4660] 29 Dec 15:54:02 - 0 clients connected (0 slaves), 922304 bytes in use
^C
@rafaelrinaldi
Copy link

brew versions {formula}

You show now see a list of formulas, then:

cd /usr/local && git checkout {sha} {repo_url}

Then just activate the version you want:

brew switch {formula} {version}

@jseaidou
Copy link

what would be the usage if I want to download from homebrew-php repo instead of the homebrew repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment