homebrew - how to install older versions


Homebrew Problem Overview

I'm trying to install memcached with older versions (ex: 1.4.5) but I'm not sure how to do it.

brew install memcached installs the latest.

I also tried brew install memecached1.4.5 but it didn't work.

Homebrew Solutions

Solution 1 - Homebrew

Usually, you can check if multiple versions are available and you can specify the version with @. e.g. brew install [email protected]

$ brew info memcached

memcached: stable 1.4.24
High performance, distributed memory object caching system
Conflicts with:
  mysql-cluster (because both install `bin/memcached`)
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/memcached.rb

If is not available the version you want you can go to the repo, and check the history

cd "$(brew --repo homebrew/core)"
git log master -- Formula/memcached.rb

Then you can find the commit you are looking for

commit 5ec463decefeaab3d1825b923ad2dbee73ffc6dc
Author: Adam Vandenberg <flangy@gmail.com>
Date:   Fri Apr 9 21:19:48 2010 -0700

    Update memcached to 1.4.5

Checkout that version and install:

cd "$(brew --repo homebrew/core)" && git checkout 5ec463decefeaab3d1825b923ad2dbee73ffc6dc
HOMEBREW_NO_AUTO_UPDATE=1 brew install memcached

Once you get the version installed:

git checkout master  # bring brew back to its latest version
brew pin memcached   # [optional] prevent formula from updating

and, that's it!

Solution 2 - Homebrew

I would do

brew unlink memecached
brew install memecached@1.4.5
brew link memecached@1.4.5 --force

Solution 3 - Homebrew

A more expanded version of the good answer from Adrian is also here on SO.


One thing to keep in mind is that if you are installing an older Formula the Homebrew API/methods may have changed since that time so you should brew edit appFormula against the current version and compare to the brew edit [email protected] if you encounter any errors trying to brew install [email protected] after the brew extract command in the answer linked.

Solution 4 - Homebrew

2021 update:

$ curl https://raw.githubusercontent.com/Homebrew/homebrew-cask/<commit-hash>/Casks/<FORMULA>.rb > $(find $(brew --repository) -name <FORMULA>.rb)
$ brew reinstall <FORMULA>

You can find the cask or formula file URL here and the commit message should describe the file version to grab the URL for.


Credit: https://remarkablemark.org/blog/2017/02/03/install-brew-package-version/

Solution 5 - Homebrew

Sharing an interactive oneliner I made for myself of Adrian's answer now:

It does a simple parsing, depending only on "/blob/" in the github URL, of "From" in brew info, and does a bash select of commit from git log.

brew install can be replaced with brew reinstall as needed.

Tested (for cask "name=powershell") in bash 5.1 (from macports ;P) and env -i /bin/bash 3.2 on macOS (High Sierra) 10.13.6 against brew 3.3.11. (I might have done some tap'ing the other day.)

(name= && { [[ $name ]]||read -ep "Name: " name;} && [[ $(brew info "$name"|sed -Ene'/^From: (.*)/s//\1/p') =~ ([^/]*)/blob/([^/]*)/([^/]*)/([^/]*) ]] && V=("${BASH_REMATCH[@]:1}") && N=(repo current dir file) && for s in ${!N[@]};do eval "${N[s]}=\${V[s]}" && declare -p >&2 "${N[s]}";done && cd "$(brew --repo "${repo//-//}")" && IFSO="$IFS" && IFS=$'\n' && select line in $(git log --oneline master -- "$dir/$file");do IFS="$IFSO" && commit=($line) && break;done && set -x && git checkout "$commit" && HOMEBREW_NO_AUTO_UPDATE=1 brew install "$name" && git checkout master)

Skål, salud, cheers!


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHenry DangView Question on Stackoverflow
Solution 1 - HomebrewAdrianView Answer on Stackoverflow
Solution 2 - HomebrewRadu ChiriacView Answer on Stackoverflow
Solution 3 - Homebrewdragon788View Answer on Stackoverflow
Solution 4 - HomebrewRyan MarvinView Answer on Stackoverflow
Solution 5 - HomebrewvikeView Answer on Stackoverflow