70

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.

3

6 Answers 6

165

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
https://memcached.org/
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 <[email protected]>
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!

7
  • 1
    If you already have it installed, you might need to do HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade memcached instead. Commented Dec 5, 2017 at 18:30
  • 25
    This works but I feel like this process should be much easier. Installing older versions isn't that uncommon of a use case
    – jvans
    Commented Jan 5, 2018 at 0:24
  • 6
    To view the full log, you might have to run git -C "$(brew --repo homebrew/core)" fetch --unshallow since brew has a shallow clone of the repository by default.
    – Philip
    Commented Feb 1, 2018 at 22:56
  • 10
    Also, brew pin memcached will keep it from being upgraded automatically in the future.
    – Philip
    Commented Feb 1, 2018 at 23:00
  • 1
    brew tap --force homebrew/core may be required on the current version of homebrew before cd "$(brew --repo homebrew/core)". Then brew untap homebrew/core as the last step to clean up.
    – Toreno96
    Commented Jan 2 at 9:51
13

This works in 2019

brew unlink memecached
brew install [email protected]
brew link [email protected] --force
2
  • 11
    ==> Searching taps on GitHub... Error: No formulae found in taps.
    – wakedeer
    Commented May 23, 2020 at 11:28
  • @Madeo what is the name of the formulae you're trying to install? Maybe you need to tap that first (Tapping means adding their external repository into brew) Commented Mar 8, 2021 at 8:05
5

If the version you are looking for was already deleted from the Homebrew repository:

  1. Find the formula in the Homebrew repo. For example, I needed solr.
  2. Go to the file History and find the version you need. For example, I needed solr 8.11.2.
  3. Get the Raw link to the file and get it locally. For my case:
    curl -o /tmp/solr.rb https://raw.githubusercontent.com/Homebrew/homebrew-core/8400730997ae589261783a1973896d2c3cdd6791/Formula/solr.rb
    
  4. Install the formula but make sure the autoupdate is turned off. For my case:
    HOMEBREW_NO_AUTO_UPDATE=1 brew install --formula /tmp/solr.rb
    
  5. Pin the formula so that it is not updated by accident. For my case:
    brew pin solr
    
  6. Follow homebrew instructions as usual.
4

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.

https://github.com/Homebrew/homebrew-core/commits/master/Formula/<formula>.rb
https://github.com/Homebrew/homebrew-cask/commits/master/Casks/<cask>.rb

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

1
  • 1
    A few field notes here: The first curl in the first snippet is indeed a cask, modify to formula if needed using the second snippet. Also, you don't have to copy the entirety of the commit hash, 7 chars suffice.
    – Dr1Ku
    Commented Nov 22, 2021 at 13:59
2

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

https://stackoverflow.com/a/53766019/3794873

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.

1

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.