58

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.

Ronan Boiteau
  • 8,910
  • 6
  • 33
  • 52
Henry Dang
  • 683
  • 1
  • 9
  • 12
  • 14
    Possible duplicate of [Homebrew install specific version of formula?](http://stackoverflow.com/questions/3987683/homebrew-install-specific-version-of-formula) – Alexander O'Mara Aug 28 '16 at 03:42
  • Answer covered here: https://stackoverflow.com/questions/3987683/homebrew-install-specific-version-of-formula – François DELAGE Aug 07 '17 at 13:03
  • Answer at https://stackoverflow.com/questions/3987683/homebrew-install-specific-version-of-formula not worky for me, this one does – gregfqt Sep 23 '18 at 14:44

5 Answers5

146

Usually, you can check if multiple versions are available and you can specify the version with @. e.g. brew install package@2.8

$ 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 <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!

Kache
  • 13,141
  • 11
  • 49
  • 74
Adrian
  • 8,122
  • 4
  • 35
  • 33
  • If you already have it installed, you might need to do `HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade memcached` instead. – Simon Woodside Dec 05 '17 at 18:30
  • 12
    This works but I feel like this process should be much easier. Installing older versions isn't that uncommon of a use case – jvans Jan 05 '18 at 00:24
  • 1
    This is a life-saving recipe, great job!! – Karol Z Jan 10 '18 at 00:07
  • 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 Feb 01 '18 at 22:56
  • 10
    Also, `brew pin memcached` will keep it from being upgraded automatically in the future. – Philip Feb 01 '18 at 23:00
  • Thank you so much for this - this was a lifesaver. fwiw this is a hilariously rediculous workaround for the most basic usage of a package manager – Robin Kurosawa Oct 11 '21 at 14:40
8

I would do

brew unlink memecached
brew install memecached@1.4.5
brew link memecached@1.4.5 --force
Radu Chiriac
  • 1,276
  • 2
  • 16
  • 31
  • 7
    ==> Searching taps on GitHub... Error: No formulae found in taps. – wakedeer May 23 '20 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) – Radu Chiriac Mar 08 '21 at 08:05
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 app@your.version if you encounter any errors trying to brew install app@your.version after the brew extract command in the answer linked.

dragon788
  • 3,133
  • 1
  • 34
  • 45
2

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/

Ryan Marvin
  • 131
  • 1
  • 4
  • 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 `char`s suffice. – Dr1Ku Nov 22 '21 at 13:59
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!

vike
  • 177
  • 3
  • 7