How to install amap in homebrew? - homebrew

I got the following error. Could anybody let me know how to install it in homebrew? Thanks.
$ brew install amap
Error: amap has been disabled because it is not maintained upstream!

Yeah, the formula is disabled, and the technical details are in here.
If you want to try out the pre-built bottle, you can use this hacky solution:
brew edit amap
comment out or remove that disable! line
save the change
brew install amap
revert the disable! change by git -C $(brew --repo homebrew/core) checkout HEAD -- Formula/amap.rb
here is my installation result.
$ brew install amp
==> Downloading https://homebrew.bintray.com/bottles/amp-0.6.2.moja
Already downloaded: /Users/rchen/Library/Caches/Homebrew/downloads/8186d3a7491dd11a17933819130d1f56d2b39fa521815d9b4d0831be93a79fe5--amp-0.6.2.mojave.bottle.tar.gz
==> Pouring amp-0.6.2.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/amp/0.6.2: 8 files, 4.3MB

Looks like the formula on homebrew was recently edited to prevent installs on MacOS Sierra. Time to patch the src or upgrade. See here: https://github.com/Homebrew/homebrew-core/commit/e3a76a8d38f396d26b82464c3e7c6b54b0b9a112#diff-82c69a605f5b89b1aab28ae16242992798c78688166b168557f9f2066734d343

Related

Homebrew error installing tomcat

After installing tomcat on Os x El Capitan using Homebrew I have received the following Warning:
your HOMEBREW_PREFIX is set to /usr/local but HOMEBREW_CELLAR is set
to /usr/local/Cellar. Your current HOMEBREW_CELLAR location will stop
you being able to use all the binary packages (bottles) Homebrew
provides. We recommend you move your HOMEBREW_CELLAR to
/usr/local/Cellar which will get you access to all bottles."
The command brew services list shows no services installed.
Printenv doesn't show any homebrew variable
It's not clear to me what should I do.
enter link description here
I also encountered this problem, in the end of the page to get accurate help,
brew bundle dump
rm -rf /usr/local/Homebrew/Cellar
brew bundle
I have received a similar warning when I tried to do a brew update.
It did not allow me to update. All I have done to resolve it was do a brew update in going to the /usr/local/Cellar directory.
From what I understand HOMEBREW_REPOSITORY path was modified or went missing when the OS was updated. After the brew update, the message said
Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew!
Homebrew no longer needs to have ownership of /usr/local. If you wish you can
return /usr/local to its default ownership with:
sudo chown root:wheel /usr/local
This got me back to my normal brew usage with out a problem.

Brew - Install specific version of brew package [duplicate]

How do I install a specific version of a formula in homebrew? For example, postgresql-8.4.4 instead of the latest 9.0.
TLDR: brew install postgresql#8.4.4 See answer below for more details.
*(I’ve re-edited my answer to give a more thorough workflow for installing/using older software versions with homebrew. Feel free to add a note if you found the old version better.)
Let’s start with the simplest case:
1) Check, whether the version is already installed (but not activated)
When homebrew installs a new formula, it puts it in a versioned directory like /usr/local/Cellar/postgresql/9.3.1. Only symbolic links to this folder are then installed globally. In principle, this makes it pretty easy to switch between two installed versions. (*)
If you have been using homebrew for longer and never removed older versions (using, for example brew cleanup), chances are that some older version of your program may still be around. If you want to simply activate that previous version, brew switch is the easiest way to do this.
Check with brew info postgresql (or brew switch postgresql <TAB>) whether the older version is installed:
$ brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M)
Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
# … and some more
We see that some older version is already installed. We may activate it using brew switch:
$ brew switch postgresql 9.1.5
Cleaning /usr/local/Cellar/postgresql/9.1.5
Cleaning /usr/local/Cellar/postgresql/9.3.2
384 links created for /usr/local/Cellar/postgresql/9.1.5
Let’s double-check what is activated:
$ brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M) *
Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M)
Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
# … and some more
Note that the star * has moved to the newly activated version
(*) Please note that brew switch only works as long as all dependencies of the older version are still around. In some cases, a rebuild of the older version may become necessary. Therefore, using brew switch is mostly useful when one wants to switch between two versions not too far apart.
2) Check, whether the version is available as a tap
Especially for larger software projects, it is very probably that there is a high enough demand for several (potentially API incompatible) major versions of a certain piece of software. As of March 2012, Homebrew 0.9 provides a mechanism for this: brew tap & the homebrew versions repository.
That versions repository may include backports of older versions for several formulae. (Mostly only the large and famous ones, but of course they’ll also have several formulae for postgresql.)
brew search postgresql will show you where to look:
$ brew search postgresql
postgresql
homebrew/versions/postgresql8 homebrew/versions/postgresql91
homebrew/versions/postgresql9 homebrew/versions/postgresql92
We can simply install it by typing
$ brew install homebrew/versions/postgresql8
Cloning into '/usr/local/Library/Taps/homebrew-versions'...
remote: Counting objects: 1563, done.
remote: Compressing objects: 100% (943/943), done.
remote: Total 1563 (delta 864), reused 1272 (delta 620)
Receiving objects: 100% (1563/1563), 422.83 KiB | 339.00 KiB/s, done.
Resolving deltas: 100% (864/864), done.
Checking connectivity... done.
Tapped 125 formula
==> Downloading http://ftp.postgresql.org/pub/source/v8.4.19/postgresql-8.4.19.tar.bz2
# …
Note that this has automatically tapped the homebrew/versions tap. (Check with brew tap, remove with brew untap homebrew/versions.) The following would have been equivalent:
$ brew tap homebrew/versions
$ brew install postgresql8
As long as the backported version formulae stay up-to-date, this approach is probably the best way to deal with older software.
3) Try some formula from the past
The following approaches are listed mostly for completeness. Both try to resurrect some undead formula from the brew repository. Due to changed dependencies, API changes in the formula spec or simply a change in the download URL, things may or may not work.
Since the whole formula directory is a git repository, one can install specific versions using plain git commands. However, we need to find a way to get to a commit where the old version was available.
a) historic times
Between August 2011 and October 2014, homebrew had a brew versions command, which spat out all available versions with their respective SHA hashes. As of October 2014, you have to do a brew tap homebrew/boneyard before you can use it. As the name of the tap suggests, you should probably only do this as a last resort.
E.g.
$ brew versions postgresql
Warning: brew-versions is unsupported and may be removed soon.
Please use the homebrew-versions tap instead:
https://github.com/Homebrew/homebrew-versions
9.3.2 git checkout 3c86d2b Library/Formula/postgresql.rb
9.3.1 git checkout a267a3e Library/Formula/postgresql.rb
9.3.0 git checkout ae59e09 Library/Formula/postgresql.rb
9.2.4 git checkout e3ac215 Library/Formula/postgresql.rb
9.2.3 git checkout c80b37c Library/Formula/postgresql.rb
9.2.2 git checkout 9076baa Library/Formula/postgresql.rb
9.2.1 git checkout 5825f62 Library/Formula/postgresql.rb
9.2.0 git checkout 2f6cbc6 Library/Formula/postgresql.rb
9.1.5 git checkout 6b8d25f Library/Formula/postgresql.rb
9.1.4 git checkout c40c7bf Library/Formula/postgresql.rb
9.1.3 git checkout 05c7954 Library/Formula/postgresql.rb
9.1.2 git checkout dfcc838 Library/Formula/postgresql.rb
9.1.1 git checkout 4ef8fb0 Library/Formula/postgresql.rb
9.0.4 git checkout 2accac4 Library/Formula/postgresql.rb
9.0.3 git checkout b782d9d Library/Formula/postgresql.rb
As you can see, it advises against using it. Homebrew spits out all versions it can find with its internal heuristic and shows you a way to retrieve the old formulae. Let’s try it.
# First, go to the homebrew base directory
$ cd $( brew --prefix )
# Checkout some old formula
$ git checkout 6b8d25f Library/Formula/postgresql.rb
$ brew install postgresql
# … installing
Now that the older postgresql version is installed, we can re-install the latest formula in order to keep our repository clean:
$ git checkout -- Library/Formula/postgresql.rb
brew switch is your friend to change between the old and the new.
b) prehistoric times
For special needs, we may also try our own digging through the homebrew repo.
$ cd Library/Taps/homebrew/homebrew-core && git log -S'8.4.4' -- Formula/postgresql.rb
git log -S looks for all commits in which the string '8.4.4' was either added or removed in the file Library/Taps/homebrew/homebrew-core/Formula/postgresql.rb. We get two commits as a result.
commit 7dc7ccef9e1ab7d2fc351d7935c96a0e0b031552
Author: Aku Kotkavuo
Date: Sun Sep 19 18:03:41 2010 +0300
Update PostgreSQL to 9.0.0.
Signed-off-by: Adam Vandenberg
commit fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422
Author: David Höppner
Date: Sun May 16 12:35:18 2010 +0200
postgresql: update version to 8.4.4
Obviously, fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422 is the commit we’re interested in. As this commit is pretty old, we’ll try to downgrade the complete homebrew installation (that way, the formula API is more or less guaranteed to be valid):
$ git checkout -b postgresql-8.4.4 fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422
$ brew install postgresql
$ git checkout master
$ git branch -d postgresql-8.4.4
You may skip the last command to keep the reference in your git repository.
One note: When checking out the older commit, you temporarily downgrade your homebrew installation. So, you should be careful as some commands in homebrew might be different to the most recent version.
4) Manually write a formula
It’s not too hard and you may then upload it to your own repository. Used to be Homebrew-Versions, but that is now discontinued.
A.) Bonus: Pinning
If you want to keep a certain version of, say postgresql, around and stop it from being updated when you do the natural brew update; brew upgrade procedure, you can pin a formula:
$ brew pin postgresql
Pinned formulae are listed in /usr/local/Library/PinnedKegs/ and once you want to bring in the latest changes and updates, you can unpin it again:
$ brew unpin postgresql
Simple Workflow
Now that Homebrew/versions has been deprecated, Homebrew/core supports a few versions of formulae with a new naming format.
To install a specific version, e.g. postgresql 9.5 you simply run:
$ brew install postgresql#9.5
To list the available versions run a search with #:
$ brew search postgresql#
==> Searching local taps...
postgresql#10.1 ✔ postgresql#9.4 postgresql#9.5 postgresql#9.6
⚠ This answer won't work anymore after December 2020:
brew switch got disabled in HomeBrew 2.7.0 (deprecated in 2.6.0)
For versions of Homebrew before 2.7:
There's now a much easier way to install an older version of a formula that you'd previously installed. Simply use
brew switch [formula] [version]
For instance, I alternate regularly between Node.js 0.4.12 and 0.6.5:
brew switch node 0.4.12
brew switch node 0.6.5
Since brew switch just changes the symlinks, it's very fast. See further documentation on the Homebrew Wiki under External Commands.
Update: 1/15/2015
Find the commit history of the desired software and version. e.g. I need to switch from docker version 1.4.1 to 1.3.3:
https://github.com/Homebrew/homebrew-core/commits/master/Formula/docker.rb
View the file with this button:
Click the Raw button:
Copy the URL (docker.rb url in this example) from address bar
brew install <url> (may have to brew unlink first, e.g. brew unlink docker)
brew switch docker 1.3.3
Switch back to docker 1.4.1 brew switch docker 1.4.1
From this gist
brew update
brew versions FORMULA
cd `brew --prefix`
git checkout HASH Library/Formula/FORMULA.rb # use output of "brew versions"
brew install FORMULA
brew switch FORMULA VERSION
git checkout -- Library/Formula/FORMULA.rb # reset formula
## Example: Using Subversion 1.6.17
#
# $ brew versions subversion
# 1.7.3 git checkout f8bf2f3 /usr/local/Library/Formula/subversion.rb
# 1.7.2 git checkout d89bf83 /usr/local/Library/Formula/subversion.rb
# 1.6.17 git checkout 6e2d550 /usr/local/Library/Formula/subversion.rb
# 1.6.16 git checkout 83ed494 /usr/local/Library/Formula/subversion.rb
# 1.6.15 git checkout 809a18a /usr/local/Library/Formula/subversion.rb
# 1.6.13 git checkout 7871a99 /usr/local/Library/Formula/subversion.rb
# 1.6.12 git checkout c99b3ac /usr/local/Library/Formula/subversion.rb
# 1.6.6 git checkout 8774131 /usr/local/Library/Formula/subversion.rb
# 1.6.5 git checkout a82e823 /usr/local/Library/Formula/subversion.rb
# 1.6.3 git checkout 6b6d369 /usr/local/Library/Formula/subversion.rb
# $ cd `brew --prefix`
# $ git checkout 6e2d550 /usr/local/Library/Formula/subversion.rb
# $ brew install subversion
# $ brew switch subversion 1.6.17
# $ git checkout -- Library/Formula/subversion.rb
Along the lines of #halfcube's suggestion, this works really well:
Find the library you're looking for at
https://github.com/Homebrew/homebrew-core/tree/master/Formula
Click it: https://github.com/Homebrew/homebrew-core/blob/master/Formula/postgresql.rb
Click the "history" button to look at old commits: https://github.com/Homebrew/homebrew-core/commits/master/Formula/postgresql.rb
Click the one you want: "postgresql: update version to 8.4.4", https://github.com/Homebrew/homebrew-core/blob/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb
Click the "raw" link: https://raw.githubusercontent.com/Homebrew/homebrew-core/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb
Solution
brew extract --version=8.4p1 openssh homebrew/cask
brew install openssh#8.4p1
The newest openssl#8.5p1 has bugs after I run brew upgrade, so I backed to the previous version successfully via the above way.
I've discovered a better alternative solution then the other complex solutions.
brew install https://raw.github.com/Homebrew/homebrew-versions/master/postgresql8.rb
This will download and install PostgreSQL 8.4.8
I found this solution by starting to follow the steps of searching the repo and a comment in the repo .
After a little research found that someone has a collection of rare formulars to brew up with.
If your looking for MySQL 5.1.x, give this a try.
brew install https://raw.github.com/Homebrew/homebrew-versions/master/mysql51.rb
UPDATE: This method is deprecated and no longer works.
This method results in error: Installation of mysql from a GitHub commit URL is unsupported! brew extract mysql to a stable tap on GitHub instead. (UsageError)
$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
...
Traceback (most recent call last):
9: from /usr/local/Homebrew/Library/Homebrew/brew.rb:122:in `<main>'
8: from /usr/local/Homebrew/Library/Homebrew/cmd/install.rb:132:in `install'
7: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:302:in `parse'
6: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `formulae'
5: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `map'
4: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:655:in `block in formulae'
3: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:351:in `factory'
2: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:138:in `get_formula'
1: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:142:in `klass'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:227:in `load_file': Invalid usage: Installation of mysql from a GitHub commit URL is unsupported! `brew extract mysql` to a stable tap on GitHub instead. (UsageError)
12: from /usr/local/Homebrew/Library/Homebrew/brew.rb:155:in `<main>'
11: from /usr/local/Homebrew/Library/Homebrew/brew.rb:157:in `rescue in <main>'
10: from /usr/local/Homebrew/Library/Homebrew/help.rb:64:in `help'
9: from /usr/local/Homebrew/Library/Homebrew/help.rb:83:in `command_help'
8: from /usr/local/Homebrew/Library/Homebrew/help.rb:103:in `parser_help'
7: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:302:in `parse'
6: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `formulae'
5: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `map'
4: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:655:in `block in formulae'
3: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:351:in `factory'
2: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:138:in `get_formula'
1: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:142:in `klass'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:227:in `load_file': Invalid usage: Installation of mysql from a GitHub commit URL is unsupported! `brew extract mysql` to a stable tap on GitHub instead. (UsageError)
I tried to install with the recommended command, but it doesn't work in this particular instance of MySQL 5.7.10. You may have better luck with a more recent Formula.
$ brew extract --version=5.7.10 mysql homebrew/cask
==> Searching repository history
==> Writing formula for mysql from revision 0fa511b to:
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql#5.7.10.rb
$
$ brew install /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql#5.7.10.rb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 1 formula.
Error: undefined method `core_tap?' for nil:NilClass
Error: Failed to load cask: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql#5.7.10.rb
Cask 'mysql#5.7.10' is unreadable: wrong constant name #<Class:0x00007f9b9498cad8>
Warning: Treating /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql#5.7.10.rb as a formula.
==> Installing mysql#5.7.10 from homebrew/cask
==> Downloading https://homebrew.bintray.com/bottles/cmake-3.19.4.big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/278f2ad1caf664019ff7b4a7fc5493999c06adf503637447af13a617d45cf484?response-content-disposition=attachment%3Bfilenam
######################################################################## 100.0%
==> Downloading https://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.bz2
==> Downloading from https://phoenixnap.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.bz2
######################################################################## 100.0%
==> Downloading https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz
curl: (22) The requested URL returned error: 404 Not Found
Error: Failed to download resource "mysql#5.7.10"
Download failed: https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz
You could modify the Formula at the path above (written in ruby) to attempt to achieve your desired result (e.g., an installation of MySQL 5.7.10 on a recent macOS version).
You can use the strategy of identifying the formula and a particular commit in the history of the formula that matches the version of the package you'd like to install.
Go to https://github.com/Homebrew/homebrew-core
Press t on your keyboard to activate the file finder.
Identify a formula that looks most relevant, perhaps: Formula/mysql.rb, bringing you to a forumla file location: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb.
Look at the revision history by clicking on the History button, which is located at https://github.com/Homebrew/homebrew-core/commits/master/Formula/mysql.rb. If you're interested in MySQL 5.7.10, you might want to click the latest revision prior to 5.7.11, which navigates to a GitHub commit:
https://github.com/Homebrew/homebrew-core/commit/c77882756a832ac1d87e7396c114158e5619016c#Formula/mysql.rb
NOTE: You may have to view the commit history in your console per GitHub's suggestion if the commit history does not load in your browser. Replace the commit SHA above in the URL if you're interested in seeing that commit on GitHub. Alternatively, skip to step 7, below.
Click the "View" button to view the source for the mysql.rb file after the commit was applied.
Then click the "Raw" button to view the raw source.
Copy the URL. Alternatively, build the URL yourself with the mysql.rb file name to identify your formula and the particular version of that formula (identified by the commmit SHA in the URL below).
https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
Install it with $ brew install [URL from step 7]
$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
Most of the other answers are obsolete by now. Unfortunately Homebrew still doesn’t have a builtin way of installing an outdated version, unless that version exists as a separate formula (e.g. python#2, postgresql#9.4 …).
Luckily, for other formulas there’s a much easier way than the convoluted mess that used to be necessary. Here are the full instructions:
Search for the correct version in the logs:
brew log formula
# Scroll down/up with j/k or the arrow keys
# or use eg. /4\.4\.23 to search a specific version
# This syntax only works on pre-2.0 Homebrew versions
brew log --format=format:%H\ %s -F --grep=‹version› ‹formula›
This will show a list of commit hashes. Take one that is appropriate (mostly it should be pretty obvious, and usually is the most recent (i.e. top) one.
Find the URL at which the formula resides in the upstream repository:
brew info ‹formula› | grep ^From:
Fix the URL:
Replace github.com with raw.githubusercontent.com
Replace blob/master with the commit hash we found in the first step.
Install the desired version by replacing master in the previously found URL by the commit hash, e.g.:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/‹hash›/Formula/‹formula›.rb
(The last step may necessitate running brew unlink ‹formula› before.)
If you have copied a commit hash you want to use, you can use something like this example to install that version, replacing the value and bash with your commit hash and your desired formula.
BREW_VERSION_SHA=32353d2286f850fd965e0a48bcf692b83a6e9a41
BREW_FORMULA_NAME=bash
brew info $BREW_FORMULA_NAME \
| sed -n \
-e '/^From: /s///' \
-e 's/github.com/raw.githubusercontent.com/' \
-e 's%blob/%%' \
-e "s/master/$BREW_VERSION_SHA/p" \
| xargs brew install
This example is installing bash 4.4.23 instead of bash 5, though if you performed a brew upgrade afterward then bash 5 would get installed over top, unless you first executed brew pin bash. Instead to make this smoother WITHOUT pinning, you should first install the latest with brew install bash, then brew unlink bash, then install the older version you want per the script above, and then use brew switch bash 4.4.23 to set up the symlinks to the older version. Now a brew upgrade shouldn't affect your version of Bash. You can brew switch bash to get a list of the versions available to switch to.
Alternative using a custom local-only tap
Another way of achieving the same goal appears to be:
brew tap-new username/repo-name
# extract with a version seems to run a grep under the hood
brew extract --version='4.4.23' bash username/repo-name
brew install bash#4.4.23
# Note this "fails" when trying to grab a bottle for the package and seems to have
# some odd doubling of the version in that output, but this isn't fatal.
This creates a formula#version in your custom tap that you can install per the above example. The downside is that you probably still need to brew unlink bash and then brew link bash#4.4.23 in order to use your specific version of Bash or any other formula.
Official method ( judging from the response to https://github.com/Homebrew/brew/issues/6028 )
Unfortunately Homebrew still doesn’t have an obvious builtin way of installing an older version.
Luckily, for most formulas there’s a much easier way than the convoluted mess that used to be necessary. Here are the full instructions using bash as an example:
brew tap-new $USER/local-tap
# extract with a version seems to run a `git log --grep` under the hood
brew extract --version=4.4.23 bash $USER/local-tap
# Install your new version from the tap
brew install bash#4.4.23
# Note this "fails" trying to grab a bottle for the package and seems to have
# some odd doubling of the version in that output, but this isn't fatal.
This creates the formula#version in your custom tap that you can install per the above example. An important note is that you probably need to brew unlink bash if you had previously installed the default/latest version of the formula and then brew link bash#4.4.23 in order to use your specific version of Bash (or any other formula where you have latest and an older version installed).
A potential downside to this method is you can't easily switch back and forth between the versions because according to brew it is a "different formula".
If you want to be able to use brew switch $FORMULA $VERSION you should use the next method.
Scripted Method (Recommended)
This example shows installing the older bash 4.4.23, a useful example since the bash formula currently installs bash 5.
First install the latest version of the formula with brew install bash
then brew unlink bash
then install the older version you want per the snippets below
finally use brew switch bash 4.4.23 to set up the symlinks to your version
If you performed a brew upgrade after installing an older version without installing the latest first, then the latest would get installed clobbering your older version, unless you first executed brew pin bash.
The steps here AVOID pinning because it is easy to forget about and you might pin to a version that becomes insecure in the future (see Shellshock/etc). With this setup a brew upgrade shouldn't affect your version of Bash and you can always run brew switch bash to get a list of the versions available to switch to.
Copy and paste and edit the export lines from the code snippet below to update with your desired version and formula name, then copy and paste the rest as-is and it will use those variables to do the magic.
# This search syntax works with newer Homebrew
export BREW_FORMULA_SEARCH_VERSION=4.4.23 BREW_FORMULA_NAME=bash
# This will print any/all commits that match the version and formula name
git -C $(brew --repo homebrew/core) log \
--format=format:%H\ %s -F --all-match \
--grep=$BREW_FORMULA_SEARCH_VERSION --grep=$BREW_FORMULA_NAME
When you are certain the version exists in the formula, you can use the below:
# Gets only the latest Git commit SHA for the script further down
export BREW_FORMULA_VERSION_SHA=$(git -C $(brew --repo homebrew/core) log \
--format=format:%H\ %s -F --all-match \
--grep=$BREW_FORMULA_SEARCH_VERSION --grep=$BREW_FORMULA_NAME | \
head -1 | awk '{print $1}')
Once you have exported the commit hash you want to use, you can use this to install that version of the package.
brew info $BREW_FORMULA_NAME \
| sed -n \
-e '/^From: /s///' \
-e 's/github.com/raw.githubusercontent.com/' \
-e 's%blob/%%' \
-e "s/master/$BREW_FORMULA_VERSION_SHA/p" \
| xargs brew install
Follow the directions in the formula output to put it into your PATH or set it as your default shell.
Homebrew changed recently. Things that used to work do not work anymore. The easiest way I found to work (January 2021), was to:
Find the .rb file for my software (first go to Formulas, find the one I need and then click "History"; for CMake, this is at https://github.com/Homebrew/homebrew-core/commits/master/Formula/cmake.rb)
Pick the desired version among the revisions, e.g. 3.18.4, click three dots in the top right corner of the .rb file diff (...) and then click Raw. Copy the URL.
Unlink the old version brew unlink cmake
Installing directly from the git URL does not work anymore (brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/2bf16397f163187ae5ac8be41ca7af25b5b2e2cc/Formula/cmake.rb will fail)
Instead, download it and install from a local file curl -O https://raw.githubusercontent.com/Homebrew/homebrew-core/2bf16397f163187ae5ac8be41ca7af25b5b2e2cc/Formula/cmake.rb && brew install ./cmake.rb
Voila! You can delete the downloaded .rb file now.
I just used Homebrew to go back to Maven 2.2.1 since the simple brew install maven installed Maven 3.0.3.
First you have to leave the maven dir there so
$ brew unlink maven
Use the brew tap command
$ brew tap homebrew/versions
Cloning into '/usr/local/Library/Taps/homebrew-versions'...
remote: Counting objects: 590, done.
remote: Compressing objects: 100% (265/265), done.
remote: Total 590 (delta 362), reused 549 (delta 325)
Receiving objects: 100% (590/590), 117.49 KiB | 79 KiB/s, done.
Resolving deltas: 100% (362/362), done.
Tapped 50 formula
Now you can install the maven2 formula:
$ brew install maven2
==> Downloading http://www.apache.org/dist/maven/maven-2/2.2.1/binaries/apache-maven-2.2.1-bin.tar.gz
######################################################################## 100.0%
/usr/local/Cellar/maven2/2.2.1: 10 files, 3.1M, built in 6 seconds
$ mvn --version
Apache Maven 2.2.1 (r801777; 2009-08-06 12:16:01-0700)
Java version: 1.6.0_37
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x" version: "10.7.4" arch: "x86_64" Family: "mac"
Edit:
You can also just brew switch maven 2.2.1 to switch to a different version.
Edit:
The Apache Maven project reorganized their repo. Updated this answer to account for this change.
Upgraded Postgres by accident?
My case:
postgresql was upgraded from 11 to 12 accidentally (after running brew upgrade without arguments)
I want to keep Postgres 11.
Solution:
Stop the DB:
brew services stop postgresql
Install Postgres 11:
brew install postgresql#11
Enable it:
brew link postgresql#11 --force
(Optional) Rename DB data directory from postgres to postgres#11:
cd /usr/local/var
ls -lh
mv postgresql#11 postgresql#11-fresh-backup
mv postgres postgresql#11
Start the DB:
brew services start postgresql#11
If you have any errors, check /usr/local/var/log/postgresql#11.log (notice the #11).
Based on the workflow described by #tschundeee and #Debilski’s update 1, I automated the procedure and added cleanup in this script.
Download it, put it in your path and brewv <formula_name> <wanted_version>. For the specific OP, it would be:
cd path/to/downloaded/script/
./brewv postgresql 8.4.4
:)
None of the other answers cover this adequately for 2022, so I'm adding these instructions that are adapted from a Homebrew maintainer's answer for a similar question for installing a specific Cask version: https://stackoverflow.com/a/62765875/6310633
Uninstall your formula
brew uninstall <formula>
Switch over to your clone of the homebrew-core repo and reset to a commit containing the version you want.
cd "$(brew --prefix)/Library/Taps/homebrew/homebrew-core/Formula"
git log <formula>.rb # examine recent commits for <formula>
git reset --hard <commit-sha> # reset clone to last known-good commit for <formula>
Checkout a new branch for your version so brew won't autorefresh master after each command, install your formula, and pin it.
git checkout -b <formula>-downgrade-<version>
brew install <formula>
brew pin <formula>
Clean up
git checkout master
brew update
When you're ready to upgrade your formula, you can brew unpin <formula> and upgrade as usual.
An updated answer since that adds to what #lance-pollard already posted as working answer.
How to Install specific version of a Formula (formula used in this example is terraform):
Find your formula file, e.g: https://github.com/Homebrew/homebrew-core/blob/master/Formula/terraform.rb
Get the commit version from github’s history with https://github.com/Homebrew/homebrew-core/commits/master/Formula/terraform.rb or git log master -- Formula/terraform.rb if you have cloned the repo locally.
Get the raw git URL with the commit version of your formula: If the formula link in github.com is https://github.com/Homebrew/homebrew-core/blob/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb, your raw URL will be: https://raw.githubusercontent.com/Homebrew/homebrew-core/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb
Install it with: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb
The other answers here are great, but if you need to install an older version of the package and ensure that the package name is modified, you'll need a different approach. This is important when using scripts (in my case, PHP build scripts) which use brew --prefix package_name to determine what directory to use for compilation.
If you are using brew extract a version is added to the end of the package name which will break the brew --prefix lookup.
Here's how to install an older package version while maintaining the original package name:
# uninstall the newer version of the package that you accidentally installed
brew uninstall --ignore-dependencies icu4c
# `extract` the version you'd like to install into a custom tap
brew tap-new $USER/local-tap
brew extract --version=68.2 icu4c $USER/local-tap
# jump into the new tap you created
cd $(brew --repository $USER/local-tap)/Formula
# rename the formula
mv icu4c#68.2.rb icu4c.rb
# change the name of the formula by removing "AT682" from the `class` definition
# the exact text you'll need to remove will be different
# depending on the version you extracted
nano icu4c.rb
# then, install this specific formula directly
brew install $(brew --repository $USER/local-tap)/Formula/icu4c.rb
I wrote more about this here.
On the newest version of homebrew (0.9.5 as of this writing) there will be a specific recipe for the version of the homebrew keg you want to install. Example:
$ brew search mongodb
mongodb mongodb24 mongodb26
Then just do brew install mongodb26 like normal.
In the case that you had already installed the latest version, make sure to unlink the latest version and link the desired version: brew unlink mongodb && brew link mongodb26.
The problem with homebrew/versions is that someone has to have that specific version of software listed in the repository for you to be able to use it. Also, since brew versions is no longer supported, another solution is required. For solutions that indicate using brew switch, this will only work if you haven't done a brew cleanup since the version needs to exist on your computer.
I had a problem with wanting to install a specific older version of docker-machine which wasn't listed in homebrew/versions. I solved this using the below, which should also work for any brew installed software. The example below will use docker-machine as the package I want to downgrade from version 0.5.0 to 0.4.1.
Go to your homebrew Formula directory.
You can determine this by running brew info [any package name].
For example, brew info docker-machine gives me a line that shows me
a path - /usr/local/Cellar/docker-machine/0.5.0. This tells me that on my machine, homebrew is installed at /usr/localand my Formula
directory is located by default at /usr/local/Library/Formula
Locate the specific formula file (.rb) for your package.
Since I want to downgrade docker-machine, I can see a docker-machine.rb file.
Get the version history for this formula file .
Enter git log docker-machine.rb. This will list out the complete commit history for this file. You will see output like this:
...more
commit 20c7abc13d2edd67c8c1d30c407bd5e31229cacc
Author: BrewTestBot
Date: Thu Nov 5 16:14:18 2015 +0000
docker-machine: update 0.5.0 bottle.
commit 8f615708184884e501bf5c16482c95eff6aea637
Author: Vincent Lesierse
Date: Tue Oct 27 22:25:30 2015 +0100
docker-machine 0.5.0
Updated docker-machine to 0.5.0
Closes #45403.
Signed-off-by: Dominyk Tiller
commit 5970e1af9b13dcbeffd281ae57c9ab90316ba423
Author: BrewTestBot
Date: Mon Sep 21 14:04:04 2015 +0100
docker-machine: update 0.4.1 bottle.
commit 18fcbd36d22fa0c19406d699308fafb44e4c8dcd
Author: BrewTestBot
Date: Sun Aug 16 09:05:56 2015 +0100
docker-machine: update 0.4.1 bottle.
...more
The tricky part is to find the latest commit for the specific version you want. In the above, I can tell the latest 0.4.1 version was committed with this commit tag : commit 5970e1af9b13dcbeffd281ae57c9ab90316ba423. The commits above this point start using version 0.5.0 (git log entries are listed from latest to earliest date).
Get a previous version of the formula file.
Using the commit tag from step #3 (you can use the first 6 chars), you can get an older version of the formula file using the following:
git checkout 5970e1 docker-machine.rb
Uninstall your current package version.
Just run the normal brew commands to uninstall the current version of your package.
Ex. brew uninstall docker-machine
Install the older package version
Now, you can just run the normal brew install command and it will install the formula that you have checkout out.
Ex. brew install docker-machine
You may need to re-link by using the brew link docker-machine if necessary.
If at any time you want to revert back to the latest version of a specific package, go into the Formula directory and issue the following commands on your formula file (.rb)
git reset HEAD docker-machine.rb
git checkout -- docker-machine.rb
Then you can brew uninstall docker-machine and brew install docker-machine to get the latest version and keep it that way going forward.
Edit: 2021, this answer is no longer functional due to the github install being deprecated. (Thanks Tim Smith for update).
Install an old brew package version (Flyway 4.2.0 example)
Find your local homebrew git dir or clone Homebrew/homebrew-core locally
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/
OR
git clone git#github.com:Homebrew/homebrew-core.git
List all available versions
git log master -- Formula/flyway.rb
Copy the commit ID for the version you want and install it directly
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/793abfa325531415184e1549836c982b39e89299/Formula/flyway.rb
I've tried most of the solutions here and they are outdated. I had to combine some ideas from here with my own work. As a result I've created a script to help me do the heavy lifting which you can find here
Usage:
brewv.sh formula_name desired_version
Currently the old ways of installing specific formula versions have been deprecated. So it seems like we have to use brew edit [formula]. E.g. say we want to install an the 62.1 version of icu4c (needed e.g. for postgresql 10.5). Then you'd have to
> brew edit icu4c
# drops you to editor
Here you'd have to alter the url, version and sha256 (perhaps also mirror) to the corresponding 62.1 strings.
url "https://ssl.icu-project.org/files/icu4c/62.1/icu4c-62_1-src.tgz"
mirror "https://github.com/unicode-org/icu/releases/download/release-62-1/icu4c-62_1-src.tgz"
version "62.1"
sha256 "3dd9868d666350dda66a6e305eecde9d479fb70b30d5b55d78a1deffb97d5aa3"
then run brew reinstall icu4c to finally download the 62.1 version.
it could be done very easy for last version of brew.
brew tap homebrew/versions
brew install subversion17 # for svn 1.7 branch instead of last available
brew install postgresql8 # for postgresql 8 (which you ask)
None of these really worked for my case (Python), so I'll add my 2 cents:
cd `brew --prefix`
git log Library/Formula/python.rb
Output looks like this:
commit 9ff2d8ca791ed1bd149fb8be063db0ed6a67a6de
Author: Dominyk Tiller <dominyktiller#gmail.com>
Date: Thu Jun 30 17:42:18 2016 +0100
python: clarify pour_bottle reason
commit cb3b29b824a264895434214e191d0d7ef4d51c85
Author: BrewTestBot <brew-test-bot#googlegroups.com>
Date: Wed Jun 29 14:18:40 2016 +0100
python: update 2.7.12 bottle.
commit 45bb1e220341894bbb7de6fd3f6df20987dc14f0
Author: Rakesh <rakkesh#users.noreply.github.com>
Date: Wed Jun 29 10:02:26 2016 +0530
python 2.7.12
Closes #2452.
Signed-off-by: Tim D. Smith <git#tim-smith.us>
commit cf5da0547cd261f79d69e7ff62fdfbd2c2d646e9
Author: BrewTestBot <brew-test-bot#googlegroups.com>
Date: Fri Jun 17 20:14:36 2016 +0100
python: update 2.7.11 bottle.
...
I want version 2.7.11 so my hash is cf5da0547cd261f79d69e7ff62fdfbd2c2d646e9 (or cf5da05 for short). Next, I check out that version and install the formula python:
git checkout cf5da05
brew install python
Finally, clean up:
git checkout master
If you can't find your version with brew search <formula>, you can also try going over the commit logs for your formula to find the version you want:
here is an example for installing an older version of nginx via brew:
ngxnx formula commit log
see nginx: update 1.6.3 bottle eba75b9a1a474b9fc4df30bd0a32637fa31ec049
From there, we can install 1.6.3 with the sha and raw git url:
brew install https://raw.githubusercontent.com/Homebrew/homebrew/eba75b9a1a474b9fc4df30bd0a32637fa31ec049/Library/Formula/nginx.rb
Here my simple answer for it - was really annoyed that there is no built in solution for that so I've built my own lazy "script". Feel free to contribute 😃👍🏻
# Please define variables
packageName=<packageName>
packageVersion=<packageVersion>
# Create a new tab
brew tap-new local/$packageName
# Extract into local tap
brew extract --version=$packageVersion $packageName local/$packageName
# Verify packages is present
brew search $packageName#
# Run brew install#version as usual
brew install local/$packageName/$packageName#$packageVersion
https://gist.github.com/ArgonQQ/cff4834dab6b254cc2140bb1454b47ef
I created a tool to ease the process prescribed in this answer.
To find a package pkg with version a.b.c, run:
$ brew-install-specific pkg#a.b.c
This will list commits on the pkg homebrew formula that mention the given version along with their GitHub urls.
Matching versions:
1. pkg: update a.b.c bottle.
https://github.com/Homebrew/homebrew-core/commit/<COMMIT-SHA>
2. pkg: release a.b.c-beta
https://github.com/Homebrew/homebrew-core/commit/<COMMIT-SHA>
3. pkg a.b.c
https://github.com/Homebrew/homebrew-core/commit/<COMMIT-SHA>
Select index:
Verify the commit from the given URL, and enter the index of the selected commit.
Select index: 2
Run:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/<COMMIT-SHA>/Formula/pkg.rb
Copy and run the given command to install.
Update on the Library/Formula/postgresql.rb line 8 to
http://ftp2.uk.postgresql.org/sites/ftp.postgresql.org/source/v8.4.6/postgresql-8.4.6.tar.bz2
And MD5 on line 9 to
fcc3daaf2292fa6bf1185ec45e512db6
Save and exit.
brew install postgres
initdb /usr/local/var/postgres
Now in this stage you might face the postgresql could not create shared memory segment error, to work around that update the /etc/sysctl.conf like this:
kern.sysv.shmall=65536
kern.sysv.shmmax=16777216
Try initdb /usr/local/var/postgres again, and it should run smooth.
To run postgresql on start
launchctl load -w /usr/local/Cellar/postgresql/8.4.6/org.postgresql.postgres.plist
Hope that helps :)
I just copied an older release of elasticsearch into the /usr/local/Cellar/elasticsearch directory.
$ mkdir /usr/local/Cellar/elasticsearch/5.4.3/bin
$ cp elasticsearch /usr/local/Cellar/elasticsearch/5.4.3/bin
$ brew switch elasticsearch 5.4.3
That's it.
Maybe it's useful for anyone.
Here is how I downgrade KOPS (which does not support versioning)
# brew has a git repo on your localhost
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git remote -v
origin https://github.com/Homebrew/homebrew-core (fetch)
origin https://github.com/Homebrew/homebrew-core (push)
# find the version of kops.rb you need
git log Formula/kops.rb
# checkout old commit
# kops: update 1.18.1 bottle.
git checkout 2f0ede7f27dfc074d5b5493894f3468f27cc73f0 -- Formula/kops.rb
brew unlink kops
brew install kops
# now we have old version installed
ls -1 /usr/local/Cellar/kops/
1.18.1
1.18.2
which kops
/usr/local/bin/kops
ls -l /usr/local/bin/kops
/usr/local/bin/kops -> ../Cellar/kops/1.18.1/bin/kops
kops version
Version 1.18.1
# revert to the newest version
brew uninstall kops
git checkout -f
brew link kops
kops version
Version 1.18.2

Can't get Homebrew and git to work the way I want them to

First off, I'm sorry for any silly mistakes on my part. I'm just starting with OneMonthRails, and this is all very new to me. My problem is with Homebrew and git. I'm told that my problem has to do with environmental variables, and I've done enough research to be confident this is correct. Ok, here's the details:
I've tried to install Homebrew, but ran into a snag with Xcode being absent. Was running OSX 10.6.8, and had to upgrade to at least 10.7.x to install the latest Xcode. I upgraded to OSX 10.8.4 and installed Xcode and reran the following line
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
I get the following script:
==> Installation successful!
You should run `brew doctor' *before* you install anything.
Now type: brew help
I am installing Homebrew so that I can install ImageMagick in order to run the Paperclip gem, so I take the advice of my Terminal about running $ brew doctor.
$ brew doctor
produces the line
Warning: Experimental support for using Xcode without the "Command Line Tools".
You have only installed Xcode. If stuff is not building, try installing the
"Command Line Tools" package provided by Apple.
Warning: Broken symlinks were found. Remove them with `brew prune`:
///long list of broken symlinks///
Warning: An outdated version of Git was detected in your PATH.
Git 1.7.10 or newer is required to perform checkouts over HTTPS from GitHub.
Please upgrade: brew upgrade git
I want to know what my git version is so I run the following script:
$ git --version
and that produces the following line:
git version 1.7.9.6
I identify where my git is located:
$ which git
and that brings:
/opt/sm/pkg/active/bin/git
After some more research, I find out that I can upgrade my git with the following script:
$ brew install git
The final line of the resulting script is a warning:
Warning: This keg was marked linked already, continuing anyway
==> Summary
🍺 /usr/local/Cellar/git/1.8.3.2: 1325 files, 28M, built in 45 seconds
I verify my git upgrade
$ git --version
git version 1.7.9.6
sudo think...maybe I need to run upgrade instead of install.
///restart computer///
$ brew upgrade git
Error: git-1.8.3.2 already installed
hmm... try doctor again
$ brew doctor
Warning: Experimental support for using Xcode without the "Command Line Tools".
You have only installed Xcode. If stuff is not building, try installing the
"Command Line Tools" package provided by Apple.
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
$ git --version
git version 1.8.3.2
YAY! I DID SOMETHING RIGHT! Now to finish with Homebrew so I can move on to installing ImageMagick:
$ brew doctor
Warning: Experimental support for using Xcode without the "Command Line Tools".
You have only installed Xcode. If stuff is not building, try installing the
"Command Line Tools" package provided by Apple.
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Arrg... I just installed Xcode. How do I install Command Line Tools? And what is this config Warning? I check it on StackOverflow, and it leads me here:
(.../questions/15225312/brew-doctor-gives-out-warnings)
I don't exactly know what I'm doing, so the following is kinda stupid
$ $PATH
nope
$ echo $PATH
nothing...
$ export PATH=/sm/pkg/active/bin/
nothing
$ export PATH= /sm/pkg/active/bin/
-bash: export: `/sm/pkg/active/bin/': not a valid identifier
(notice the space after the =)
I realize just how much I don't know what I'm doing, so I ask for help
$ brew help
-bash: brew: No such file or directory
uh oh...
$ brew doctor
-bash: brew: No such file or directory
I think I broke my computer, guys. What should I do??? I need to get Homebrew functioning so that I can install the ImageMagick image processor and use the Paperclip gem in Rails.
:((
I know it's super frustrating and some what confusing to get this all to work. Been there, done that.
There are a couple things at play here, so take them one at a time (in fact. I'm just guessing some stuff so I'm happy to update this answer as you let me know more)
Let's start with:
Warning: Experimental support for using Xcode without the "Command Line Tools". You have only installed Xcode. If stuff is not building, try installing the "Command Line Tools" package provided by Apple.
Installing command line tools is highly recommended. It's going to install gcc and other tools that help compile the code that homebrew downloads.
Open Xcode.
Open Preferences.
On the top bar, choose "Downloads"
Install "Command line tools"
Second, I'm not sure how you quite blew away your path. I would first see if you just messed up this terminal and if you close it and start a new terminal window if your PATH is okay.
However, failing that, here's a path that has some basic search paths that will help you get on your way:
export PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin:/usr/local/sbin
You should probably check your .zshrc/.zsh_profile or .bashrc/.bash_profile and see what you are setting your PATH to.
You won't want the space on either side of the = when you are typing that command.
I recently tried the upgrade from 10.6 to 10.8 (to install rails, bundler, RVM) and had lots of the same problems with brew and RVM conflicting AND having their own separate problems (PATH, permissions/non-writable folders, old versions XCode etc). It went off without problems after i tripled backed up everything (TMachine, git and manually copying selected directory trees) and did the clean Mountain Lion install off a USB drive.
If you're only having PATH problems, you could edit it manually/temporarily (until next time .bashrc is run, per comment to the answer: Brew doctor gives out warnings

Getting a "bad interpreter" error when using brew

I'm getting this error when I try to run any brew command.
Holger-Sindbaeks-MacBook-Air:~ holgersindbaek$ brew help
-bash: /usr/local/bin/brew: /usr/bin/ruby: bad interpreter: No such file or directory
I have absolutely no idea on how to fix this and been searching for a long time without answer.
I got this error (much the same):
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 26: /usr/local/Library/brew.rb: Undefined error: 0
and fixed by the solution below:
Open brew.rb:
$ sudo vim /usr/local/Library/brew.rb
Change the first line's 1.8 to Current:
Before:
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0
After:
#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0
Then brew works for me. Hope it helps if any other one got this issue. :)
If you get the error
Homebrew requires Leopard or higher. For Tiger support, see:
https://github.com/mistydemeo/tigerbrew
change the MACOS check from <10.5 to <10.
Tip by #TimCastelijns:
10.5 doesn't work because in comparison, it's higher than 10.10 (.1 vs .5). I added a check (and MACOS_VERSION != 10.10) instead of lowering from 10.5 to 10.
What you are getting means that Homebrew has not been able to locate the Ruby interpretter at the specified location.
Install Apple Developer Kit (comes with Xcode) which should be available to you as an optional install (or you can simply download it from Apple). This will install the Ruby interpreter for you.
In case you already have Xcode installed, this means that one of these things is happening:
You have a broken Ruby installation
You have more than one Ruby installation
Your installation has not been configured properly.
To identify if this is the first case, you can run ruby and see if you get any response.
If you don't, your installation is broken and you need to reinstall it. If you do, you then run which ruby. This should give you the absolute path to your Ruby executable. If this is anything other than /usr/bin/ruby then homebrew (and a bunch of other programs) will not be able to find it.
In case you have not ever tampered with your Ruby installation, you can check to see if /usr/bin/ruby already exists or not: cat /usr/bin/ruby. If you get No such file or directory, then you can easily create a symbolic link to your Ruby installation. Assuming the output of which ruby to by /usr/local/bin/ruby, you create the symbolic link this way: sudo ln -s /usr/local/bin/ruby /usr/bin/ruby and all should be well.
If there is a file at that location, you can run file /usr/bin/ruby to see if it's a real file, a symbolic link, or a corrupted file. If it is a symbolic link, your installation should be working, and since it's not, it probably is either a corrupted symlink or it's a bogus file.
You can remedy that by first deleting it (sudo rm /usr/bin/ruby) and then creating a new symlink to the correct location (sudo ln -s /usr/local/bin/ruby /usr/bin/ruby).
If non of the above works, you should consult the homebrew team after a clean install of Xcode and removing any traces of a Ruby installation on your system.
EDIT
Alternatively, as pointed out by the other answers, the issue might be because of a bad ruby version in your Homebrew settings.
A quick fix might be updating your Homebrew:
cd /usr/local
git pull -q origin refs/heads/master:refs/remotes/origin/master
If this does not help, you might want to get your hands dirty and manually fix the problem by:
Editing brew.rb from /user/local/Library/brew.rb
Changing /1.8/ to /Current/ in the first line, which will cause the hashbang to point to the current Ruby version as the executor
If this does not help, either, you can also modify the MACOS check and change it from 10.5 to 10 to avoid the infamous "Homebrew requires Leopard or higher" error.
DISCLAIMER
A bunch of thanks to other contributors in the answers below and their commenters. I am not committing plagiarism, simply aggregating the answers into one integrated article to help others.
Fix:
sudo gem install cocoapods
At the risk of oversimplifying things, try running
gem install bundler
I was transitioning my Ruby environment from RBENV to RVM and it worked for me.
This happened because I needed to update brew - in the updated version it already uses Current ruby
cd /usr/local
git pull -q origin refs/heads/master:refs/remotes/origin/master
This solved the problem
You need to change the path for Ruby.Framework
I solved it with commands as mentioned.
brew install cocoapods --build-from-source
brew link --overwrite cocoapods
If you have a lower version below Xcode 11, you have to remove it before you use the above commands.
Reference: Ruby Framework issue
None of the above worked for me, so I kept browsing and found this answer,
https://stackoverflow.com/a/24225960/1359088
which did fix brew for me. He says in step 1 to install XCode 6 command line tools, but doesn't say how; use this command:
xcode-select --install
I got the same issue when updated to MacOSX High Sierra & using Xcode 9 with that. High Sierra update ruby gem to version 2.3 but xcpreety command of Xcode 9 still using Ruby 2.0 which is unable to find now & gives bad interpreter.
Just go to Terminal & run
sudo gem install xcpretty
Restart Xcode & do fresh clean build it works for me.
Hope it helps!!!
After upgrading to macOS High Sierra, get it fixed with following commands:
sudo gem install cocoapods
In my case seems like fastlane installed incorrectly with brew install fastlane system didn't write correct path to fastlane. I fixed it with alias fastlane=~/.fastlane/bin/fastlane
I solved it with commands as mentioned.
1.) Uninstall your GEM.
gem unistall GEM
2.) Then Install your GEM.
sudo gem install GEM -n /usr/local/bin
I got bad interpreter: No such file or directory error when used xcpretty and xcpretty-travis-formatter on upgraded MacOS.
To solve it
gem install xcpretty
gem install xcpretty-travis-formatter
That is why I can recommend you to reinstall failed component gem install <name>
#For example error looks like
/usr/local/bin/xcpretty-travis-formatter: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: bad interpreter: No such file or directory
#use
gem install xcpretty-travis-formatter

Homebrew install specific version of formula?

How do I install a specific version of a formula in homebrew? For example, postgresql-8.4.4 instead of the latest 9.0.
TLDR: brew install postgresql#8.4.4 See answer below for more details.
*(I’ve re-edited my answer to give a more thorough workflow for installing/using older software versions with homebrew. Feel free to add a note if you found the old version better.)
Let’s start with the simplest case:
1) Check, whether the version is already installed (but not activated)
When homebrew installs a new formula, it puts it in a versioned directory like /usr/local/Cellar/postgresql/9.3.1. Only symbolic links to this folder are then installed globally. In principle, this makes it pretty easy to switch between two installed versions. (*)
If you have been using homebrew for longer and never removed older versions (using, for example brew cleanup), chances are that some older version of your program may still be around. If you want to simply activate that previous version, brew switch is the easiest way to do this.
Check with brew info postgresql (or brew switch postgresql <TAB>) whether the older version is installed:
$ brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M)
Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
# … and some more
We see that some older version is already installed. We may activate it using brew switch:
$ brew switch postgresql 9.1.5
Cleaning /usr/local/Cellar/postgresql/9.1.5
Cleaning /usr/local/Cellar/postgresql/9.3.2
384 links created for /usr/local/Cellar/postgresql/9.1.5
Let’s double-check what is activated:
$ brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M) *
Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M)
Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
# … and some more
Note that the star * has moved to the newly activated version
(*) Please note that brew switch only works as long as all dependencies of the older version are still around. In some cases, a rebuild of the older version may become necessary. Therefore, using brew switch is mostly useful when one wants to switch between two versions not too far apart.
2) Check, whether the version is available as a tap
Especially for larger software projects, it is very probably that there is a high enough demand for several (potentially API incompatible) major versions of a certain piece of software. As of March 2012, Homebrew 0.9 provides a mechanism for this: brew tap & the homebrew versions repository.
That versions repository may include backports of older versions for several formulae. (Mostly only the large and famous ones, but of course they’ll also have several formulae for postgresql.)
brew search postgresql will show you where to look:
$ brew search postgresql
postgresql
homebrew/versions/postgresql8 homebrew/versions/postgresql91
homebrew/versions/postgresql9 homebrew/versions/postgresql92
We can simply install it by typing
$ brew install homebrew/versions/postgresql8
Cloning into '/usr/local/Library/Taps/homebrew-versions'...
remote: Counting objects: 1563, done.
remote: Compressing objects: 100% (943/943), done.
remote: Total 1563 (delta 864), reused 1272 (delta 620)
Receiving objects: 100% (1563/1563), 422.83 KiB | 339.00 KiB/s, done.
Resolving deltas: 100% (864/864), done.
Checking connectivity... done.
Tapped 125 formula
==> Downloading http://ftp.postgresql.org/pub/source/v8.4.19/postgresql-8.4.19.tar.bz2
# …
Note that this has automatically tapped the homebrew/versions tap. (Check with brew tap, remove with brew untap homebrew/versions.) The following would have been equivalent:
$ brew tap homebrew/versions
$ brew install postgresql8
As long as the backported version formulae stay up-to-date, this approach is probably the best way to deal with older software.
3) Try some formula from the past
The following approaches are listed mostly for completeness. Both try to resurrect some undead formula from the brew repository. Due to changed dependencies, API changes in the formula spec or simply a change in the download URL, things may or may not work.
Since the whole formula directory is a git repository, one can install specific versions using plain git commands. However, we need to find a way to get to a commit where the old version was available.
a) historic times
Between August 2011 and October 2014, homebrew had a brew versions command, which spat out all available versions with their respective SHA hashes. As of October 2014, you have to do a brew tap homebrew/boneyard before you can use it. As the name of the tap suggests, you should probably only do this as a last resort.
E.g.
$ brew versions postgresql
Warning: brew-versions is unsupported and may be removed soon.
Please use the homebrew-versions tap instead:
https://github.com/Homebrew/homebrew-versions
9.3.2 git checkout 3c86d2b Library/Formula/postgresql.rb
9.3.1 git checkout a267a3e Library/Formula/postgresql.rb
9.3.0 git checkout ae59e09 Library/Formula/postgresql.rb
9.2.4 git checkout e3ac215 Library/Formula/postgresql.rb
9.2.3 git checkout c80b37c Library/Formula/postgresql.rb
9.2.2 git checkout 9076baa Library/Formula/postgresql.rb
9.2.1 git checkout 5825f62 Library/Formula/postgresql.rb
9.2.0 git checkout 2f6cbc6 Library/Formula/postgresql.rb
9.1.5 git checkout 6b8d25f Library/Formula/postgresql.rb
9.1.4 git checkout c40c7bf Library/Formula/postgresql.rb
9.1.3 git checkout 05c7954 Library/Formula/postgresql.rb
9.1.2 git checkout dfcc838 Library/Formula/postgresql.rb
9.1.1 git checkout 4ef8fb0 Library/Formula/postgresql.rb
9.0.4 git checkout 2accac4 Library/Formula/postgresql.rb
9.0.3 git checkout b782d9d Library/Formula/postgresql.rb
As you can see, it advises against using it. Homebrew spits out all versions it can find with its internal heuristic and shows you a way to retrieve the old formulae. Let’s try it.
# First, go to the homebrew base directory
$ cd $( brew --prefix )
# Checkout some old formula
$ git checkout 6b8d25f Library/Formula/postgresql.rb
$ brew install postgresql
# … installing
Now that the older postgresql version is installed, we can re-install the latest formula in order to keep our repository clean:
$ git checkout -- Library/Formula/postgresql.rb
brew switch is your friend to change between the old and the new.
b) prehistoric times
For special needs, we may also try our own digging through the homebrew repo.
$ cd Library/Taps/homebrew/homebrew-core && git log -S'8.4.4' -- Formula/postgresql.rb
git log -S looks for all commits in which the string '8.4.4' was either added or removed in the file Library/Taps/homebrew/homebrew-core/Formula/postgresql.rb. We get two commits as a result.
commit 7dc7ccef9e1ab7d2fc351d7935c96a0e0b031552
Author: Aku Kotkavuo
Date: Sun Sep 19 18:03:41 2010 +0300
Update PostgreSQL to 9.0.0.
Signed-off-by: Adam Vandenberg
commit fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422
Author: David Höppner
Date: Sun May 16 12:35:18 2010 +0200
postgresql: update version to 8.4.4
Obviously, fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422 is the commit we’re interested in. As this commit is pretty old, we’ll try to downgrade the complete homebrew installation (that way, the formula API is more or less guaranteed to be valid):
$ git checkout -b postgresql-8.4.4 fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422
$ brew install postgresql
$ git checkout master
$ git branch -d postgresql-8.4.4
You may skip the last command to keep the reference in your git repository.
One note: When checking out the older commit, you temporarily downgrade your homebrew installation. So, you should be careful as some commands in homebrew might be different to the most recent version.
4) Manually write a formula
It’s not too hard and you may then upload it to your own repository. Used to be Homebrew-Versions, but that is now discontinued.
A.) Bonus: Pinning
If you want to keep a certain version of, say postgresql, around and stop it from being updated when you do the natural brew update; brew upgrade procedure, you can pin a formula:
$ brew pin postgresql
Pinned formulae are listed in /usr/local/Library/PinnedKegs/ and once you want to bring in the latest changes and updates, you can unpin it again:
$ brew unpin postgresql
Simple Workflow
Now that Homebrew/versions has been deprecated, Homebrew/core supports a few versions of formulae with a new naming format.
To install a specific version, e.g. postgresql 9.5 you simply run:
$ brew install postgresql#9.5
To list the available versions run a search with #:
$ brew search postgresql#
==> Searching local taps...
postgresql#10.1 ✔ postgresql#9.4 postgresql#9.5 postgresql#9.6
⚠ This answer won't work anymore after December 2020:
brew switch got disabled in HomeBrew 2.7.0 (deprecated in 2.6.0)
For versions of Homebrew before 2.7:
There's now a much easier way to install an older version of a formula that you'd previously installed. Simply use
brew switch [formula] [version]
For instance, I alternate regularly between Node.js 0.4.12 and 0.6.5:
brew switch node 0.4.12
brew switch node 0.6.5
Since brew switch just changes the symlinks, it's very fast. See further documentation on the Homebrew Wiki under External Commands.
Update: 1/15/2015
Find the commit history of the desired software and version. e.g. I need to switch from docker version 1.4.1 to 1.3.3:
https://github.com/Homebrew/homebrew-core/commits/master/Formula/docker.rb
View the file with this button:
Click the Raw button:
Copy the URL (docker.rb url in this example) from address bar
brew install <url> (may have to brew unlink first, e.g. brew unlink docker)
brew switch docker 1.3.3
Switch back to docker 1.4.1 brew switch docker 1.4.1
From this gist
brew update
brew versions FORMULA
cd `brew --prefix`
git checkout HASH Library/Formula/FORMULA.rb # use output of "brew versions"
brew install FORMULA
brew switch FORMULA VERSION
git checkout -- Library/Formula/FORMULA.rb # reset formula
## Example: Using Subversion 1.6.17
#
# $ brew versions subversion
# 1.7.3 git checkout f8bf2f3 /usr/local/Library/Formula/subversion.rb
# 1.7.2 git checkout d89bf83 /usr/local/Library/Formula/subversion.rb
# 1.6.17 git checkout 6e2d550 /usr/local/Library/Formula/subversion.rb
# 1.6.16 git checkout 83ed494 /usr/local/Library/Formula/subversion.rb
# 1.6.15 git checkout 809a18a /usr/local/Library/Formula/subversion.rb
# 1.6.13 git checkout 7871a99 /usr/local/Library/Formula/subversion.rb
# 1.6.12 git checkout c99b3ac /usr/local/Library/Formula/subversion.rb
# 1.6.6 git checkout 8774131 /usr/local/Library/Formula/subversion.rb
# 1.6.5 git checkout a82e823 /usr/local/Library/Formula/subversion.rb
# 1.6.3 git checkout 6b6d369 /usr/local/Library/Formula/subversion.rb
# $ cd `brew --prefix`
# $ git checkout 6e2d550 /usr/local/Library/Formula/subversion.rb
# $ brew install subversion
# $ brew switch subversion 1.6.17
# $ git checkout -- Library/Formula/subversion.rb
Along the lines of #halfcube's suggestion, this works really well:
Find the library you're looking for at
https://github.com/Homebrew/homebrew-core/tree/master/Formula
Click it: https://github.com/Homebrew/homebrew-core/blob/master/Formula/postgresql.rb
Click the "history" button to look at old commits: https://github.com/Homebrew/homebrew-core/commits/master/Formula/postgresql.rb
Click the one you want: "postgresql: update version to 8.4.4", https://github.com/Homebrew/homebrew-core/blob/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb
Click the "raw" link: https://raw.githubusercontent.com/Homebrew/homebrew-core/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb
Solution
brew extract --version=8.4p1 openssh homebrew/cask
brew install openssh#8.4p1
The newest openssl#8.5p1 has bugs after I run brew upgrade, so I backed to the previous version successfully via the above way.
I've discovered a better alternative solution then the other complex solutions.
brew install https://raw.github.com/Homebrew/homebrew-versions/master/postgresql8.rb
This will download and install PostgreSQL 8.4.8
I found this solution by starting to follow the steps of searching the repo and a comment in the repo .
After a little research found that someone has a collection of rare formulars to brew up with.
If your looking for MySQL 5.1.x, give this a try.
brew install https://raw.github.com/Homebrew/homebrew-versions/master/mysql51.rb
UPDATE: This method is deprecated and no longer works.
This method results in error: Installation of mysql from a GitHub commit URL is unsupported! brew extract mysql to a stable tap on GitHub instead. (UsageError)
$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
...
Traceback (most recent call last):
9: from /usr/local/Homebrew/Library/Homebrew/brew.rb:122:in `<main>'
8: from /usr/local/Homebrew/Library/Homebrew/cmd/install.rb:132:in `install'
7: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:302:in `parse'
6: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `formulae'
5: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `map'
4: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:655:in `block in formulae'
3: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:351:in `factory'
2: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:138:in `get_formula'
1: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:142:in `klass'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:227:in `load_file': Invalid usage: Installation of mysql from a GitHub commit URL is unsupported! `brew extract mysql` to a stable tap on GitHub instead. (UsageError)
12: from /usr/local/Homebrew/Library/Homebrew/brew.rb:155:in `<main>'
11: from /usr/local/Homebrew/Library/Homebrew/brew.rb:157:in `rescue in <main>'
10: from /usr/local/Homebrew/Library/Homebrew/help.rb:64:in `help'
9: from /usr/local/Homebrew/Library/Homebrew/help.rb:83:in `command_help'
8: from /usr/local/Homebrew/Library/Homebrew/help.rb:103:in `parser_help'
7: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:302:in `parse'
6: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `formulae'
5: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `map'
4: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:655:in `block in formulae'
3: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:351:in `factory'
2: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:138:in `get_formula'
1: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:142:in `klass'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:227:in `load_file': Invalid usage: Installation of mysql from a GitHub commit URL is unsupported! `brew extract mysql` to a stable tap on GitHub instead. (UsageError)
I tried to install with the recommended command, but it doesn't work in this particular instance of MySQL 5.7.10. You may have better luck with a more recent Formula.
$ brew extract --version=5.7.10 mysql homebrew/cask
==> Searching repository history
==> Writing formula for mysql from revision 0fa511b to:
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql#5.7.10.rb
$
$ brew install /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql#5.7.10.rb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 1 formula.
Error: undefined method `core_tap?' for nil:NilClass
Error: Failed to load cask: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql#5.7.10.rb
Cask 'mysql#5.7.10' is unreadable: wrong constant name #<Class:0x00007f9b9498cad8>
Warning: Treating /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql#5.7.10.rb as a formula.
==> Installing mysql#5.7.10 from homebrew/cask
==> Downloading https://homebrew.bintray.com/bottles/cmake-3.19.4.big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/278f2ad1caf664019ff7b4a7fc5493999c06adf503637447af13a617d45cf484?response-content-disposition=attachment%3Bfilenam
######################################################################## 100.0%
==> Downloading https://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.bz2
==> Downloading from https://phoenixnap.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.bz2
######################################################################## 100.0%
==> Downloading https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz
curl: (22) The requested URL returned error: 404 Not Found
Error: Failed to download resource "mysql#5.7.10"
Download failed: https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz
You could modify the Formula at the path above (written in ruby) to attempt to achieve your desired result (e.g., an installation of MySQL 5.7.10 on a recent macOS version).
You can use the strategy of identifying the formula and a particular commit in the history of the formula that matches the version of the package you'd like to install.
Go to https://github.com/Homebrew/homebrew-core
Press t on your keyboard to activate the file finder.
Identify a formula that looks most relevant, perhaps: Formula/mysql.rb, bringing you to a forumla file location: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb.
Look at the revision history by clicking on the History button, which is located at https://github.com/Homebrew/homebrew-core/commits/master/Formula/mysql.rb. If you're interested in MySQL 5.7.10, you might want to click the latest revision prior to 5.7.11, which navigates to a GitHub commit:
https://github.com/Homebrew/homebrew-core/commit/c77882756a832ac1d87e7396c114158e5619016c#Formula/mysql.rb
NOTE: You may have to view the commit history in your console per GitHub's suggestion if the commit history does not load in your browser. Replace the commit SHA above in the URL if you're interested in seeing that commit on GitHub. Alternatively, skip to step 7, below.
Click the "View" button to view the source for the mysql.rb file after the commit was applied.
Then click the "Raw" button to view the raw source.
Copy the URL. Alternatively, build the URL yourself with the mysql.rb file name to identify your formula and the particular version of that formula (identified by the commmit SHA in the URL below).
https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
Install it with $ brew install [URL from step 7]
$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
Most of the other answers are obsolete by now. Unfortunately Homebrew still doesn’t have a builtin way of installing an outdated version, unless that version exists as a separate formula (e.g. python#2, postgresql#9.4 …).
Luckily, for other formulas there’s a much easier way than the convoluted mess that used to be necessary. Here are the full instructions:
Search for the correct version in the logs:
brew log formula
# Scroll down/up with j/k or the arrow keys
# or use eg. /4\.4\.23 to search a specific version
# This syntax only works on pre-2.0 Homebrew versions
brew log --format=format:%H\ %s -F --grep=‹version› ‹formula›
This will show a list of commit hashes. Take one that is appropriate (mostly it should be pretty obvious, and usually is the most recent (i.e. top) one.
Find the URL at which the formula resides in the upstream repository:
brew info ‹formula› | grep ^From:
Fix the URL:
Replace github.com with raw.githubusercontent.com
Replace blob/master with the commit hash we found in the first step.
Install the desired version by replacing master in the previously found URL by the commit hash, e.g.:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/‹hash›/Formula/‹formula›.rb
(The last step may necessitate running brew unlink ‹formula› before.)
If you have copied a commit hash you want to use, you can use something like this example to install that version, replacing the value and bash with your commit hash and your desired formula.
BREW_VERSION_SHA=32353d2286f850fd965e0a48bcf692b83a6e9a41
BREW_FORMULA_NAME=bash
brew info $BREW_FORMULA_NAME \
| sed -n \
-e '/^From: /s///' \
-e 's/github.com/raw.githubusercontent.com/' \
-e 's%blob/%%' \
-e "s/master/$BREW_VERSION_SHA/p" \
| xargs brew install
This example is installing bash 4.4.23 instead of bash 5, though if you performed a brew upgrade afterward then bash 5 would get installed over top, unless you first executed brew pin bash. Instead to make this smoother WITHOUT pinning, you should first install the latest with brew install bash, then brew unlink bash, then install the older version you want per the script above, and then use brew switch bash 4.4.23 to set up the symlinks to the older version. Now a brew upgrade shouldn't affect your version of Bash. You can brew switch bash to get a list of the versions available to switch to.
Alternative using a custom local-only tap
Another way of achieving the same goal appears to be:
brew tap-new username/repo-name
# extract with a version seems to run a grep under the hood
brew extract --version='4.4.23' bash username/repo-name
brew install bash#4.4.23
# Note this "fails" when trying to grab a bottle for the package and seems to have
# some odd doubling of the version in that output, but this isn't fatal.
This creates a formula#version in your custom tap that you can install per the above example. The downside is that you probably still need to brew unlink bash and then brew link bash#4.4.23 in order to use your specific version of Bash or any other formula.
Official method ( judging from the response to https://github.com/Homebrew/brew/issues/6028 )
Unfortunately Homebrew still doesn’t have an obvious builtin way of installing an older version.
Luckily, for most formulas there’s a much easier way than the convoluted mess that used to be necessary. Here are the full instructions using bash as an example:
brew tap-new $USER/local-tap
# extract with a version seems to run a `git log --grep` under the hood
brew extract --version=4.4.23 bash $USER/local-tap
# Install your new version from the tap
brew install bash#4.4.23
# Note this "fails" trying to grab a bottle for the package and seems to have
# some odd doubling of the version in that output, but this isn't fatal.
This creates the formula#version in your custom tap that you can install per the above example. An important note is that you probably need to brew unlink bash if you had previously installed the default/latest version of the formula and then brew link bash#4.4.23 in order to use your specific version of Bash (or any other formula where you have latest and an older version installed).
A potential downside to this method is you can't easily switch back and forth between the versions because according to brew it is a "different formula".
If you want to be able to use brew switch $FORMULA $VERSION you should use the next method.
Scripted Method (Recommended)
This example shows installing the older bash 4.4.23, a useful example since the bash formula currently installs bash 5.
First install the latest version of the formula with brew install bash
then brew unlink bash
then install the older version you want per the snippets below
finally use brew switch bash 4.4.23 to set up the symlinks to your version
If you performed a brew upgrade after installing an older version without installing the latest first, then the latest would get installed clobbering your older version, unless you first executed brew pin bash.
The steps here AVOID pinning because it is easy to forget about and you might pin to a version that becomes insecure in the future (see Shellshock/etc). With this setup a brew upgrade shouldn't affect your version of Bash and you can always run brew switch bash to get a list of the versions available to switch to.
Copy and paste and edit the export lines from the code snippet below to update with your desired version and formula name, then copy and paste the rest as-is and it will use those variables to do the magic.
# This search syntax works with newer Homebrew
export BREW_FORMULA_SEARCH_VERSION=4.4.23 BREW_FORMULA_NAME=bash
# This will print any/all commits that match the version and formula name
git -C $(brew --repo homebrew/core) log \
--format=format:%H\ %s -F --all-match \
--grep=$BREW_FORMULA_SEARCH_VERSION --grep=$BREW_FORMULA_NAME
When you are certain the version exists in the formula, you can use the below:
# Gets only the latest Git commit SHA for the script further down
export BREW_FORMULA_VERSION_SHA=$(git -C $(brew --repo homebrew/core) log \
--format=format:%H\ %s -F --all-match \
--grep=$BREW_FORMULA_SEARCH_VERSION --grep=$BREW_FORMULA_NAME | \
head -1 | awk '{print $1}')
Once you have exported the commit hash you want to use, you can use this to install that version of the package.
brew info $BREW_FORMULA_NAME \
| sed -n \
-e '/^From: /s///' \
-e 's/github.com/raw.githubusercontent.com/' \
-e 's%blob/%%' \
-e "s/master/$BREW_FORMULA_VERSION_SHA/p" \
| xargs brew install
Follow the directions in the formula output to put it into your PATH or set it as your default shell.
Homebrew changed recently. Things that used to work do not work anymore. The easiest way I found to work (January 2021), was to:
Find the .rb file for my software (first go to Formulas, find the one I need and then click "History"; for CMake, this is at https://github.com/Homebrew/homebrew-core/commits/master/Formula/cmake.rb)
Pick the desired version among the revisions, e.g. 3.18.4, click three dots in the top right corner of the .rb file diff (...) and then click Raw. Copy the URL.
Unlink the old version brew unlink cmake
Installing directly from the git URL does not work anymore (brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/2bf16397f163187ae5ac8be41ca7af25b5b2e2cc/Formula/cmake.rb will fail)
Instead, download it and install from a local file curl -O https://raw.githubusercontent.com/Homebrew/homebrew-core/2bf16397f163187ae5ac8be41ca7af25b5b2e2cc/Formula/cmake.rb && brew install ./cmake.rb
Voila! You can delete the downloaded .rb file now.
I just used Homebrew to go back to Maven 2.2.1 since the simple brew install maven installed Maven 3.0.3.
First you have to leave the maven dir there so
$ brew unlink maven
Use the brew tap command
$ brew tap homebrew/versions
Cloning into '/usr/local/Library/Taps/homebrew-versions'...
remote: Counting objects: 590, done.
remote: Compressing objects: 100% (265/265), done.
remote: Total 590 (delta 362), reused 549 (delta 325)
Receiving objects: 100% (590/590), 117.49 KiB | 79 KiB/s, done.
Resolving deltas: 100% (362/362), done.
Tapped 50 formula
Now you can install the maven2 formula:
$ brew install maven2
==> Downloading http://www.apache.org/dist/maven/maven-2/2.2.1/binaries/apache-maven-2.2.1-bin.tar.gz
######################################################################## 100.0%
/usr/local/Cellar/maven2/2.2.1: 10 files, 3.1M, built in 6 seconds
$ mvn --version
Apache Maven 2.2.1 (r801777; 2009-08-06 12:16:01-0700)
Java version: 1.6.0_37
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x" version: "10.7.4" arch: "x86_64" Family: "mac"
Edit:
You can also just brew switch maven 2.2.1 to switch to a different version.
Edit:
The Apache Maven project reorganized their repo. Updated this answer to account for this change.
Upgraded Postgres by accident?
My case:
postgresql was upgraded from 11 to 12 accidentally (after running brew upgrade without arguments)
I want to keep Postgres 11.
Solution:
Stop the DB:
brew services stop postgresql
Install Postgres 11:
brew install postgresql#11
Enable it:
brew link postgresql#11 --force
(Optional) Rename DB data directory from postgres to postgres#11:
cd /usr/local/var
ls -lh
mv postgresql#11 postgresql#11-fresh-backup
mv postgres postgresql#11
Start the DB:
brew services start postgresql#11
If you have any errors, check /usr/local/var/log/postgresql#11.log (notice the #11).
Based on the workflow described by #tschundeee and #Debilski’s update 1, I automated the procedure and added cleanup in this script.
Download it, put it in your path and brewv <formula_name> <wanted_version>. For the specific OP, it would be:
cd path/to/downloaded/script/
./brewv postgresql 8.4.4
:)
None of the other answers cover this adequately for 2022, so I'm adding these instructions that are adapted from a Homebrew maintainer's answer for a similar question for installing a specific Cask version: https://stackoverflow.com/a/62765875/6310633
Uninstall your formula
brew uninstall <formula>
Switch over to your clone of the homebrew-core repo and reset to a commit containing the version you want.
cd "$(brew --prefix)/Library/Taps/homebrew/homebrew-core/Formula"
git log <formula>.rb # examine recent commits for <formula>
git reset --hard <commit-sha> # reset clone to last known-good commit for <formula>
Checkout a new branch for your version so brew won't autorefresh master after each command, install your formula, and pin it.
git checkout -b <formula>-downgrade-<version>
brew install <formula>
brew pin <formula>
Clean up
git checkout master
brew update
When you're ready to upgrade your formula, you can brew unpin <formula> and upgrade as usual.
An updated answer since that adds to what #lance-pollard already posted as working answer.
How to Install specific version of a Formula (formula used in this example is terraform):
Find your formula file, e.g: https://github.com/Homebrew/homebrew-core/blob/master/Formula/terraform.rb
Get the commit version from github’s history with https://github.com/Homebrew/homebrew-core/commits/master/Formula/terraform.rb or git log master -- Formula/terraform.rb if you have cloned the repo locally.
Get the raw git URL with the commit version of your formula: If the formula link in github.com is https://github.com/Homebrew/homebrew-core/blob/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb, your raw URL will be: https://raw.githubusercontent.com/Homebrew/homebrew-core/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb
Install it with: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb
The other answers here are great, but if you need to install an older version of the package and ensure that the package name is modified, you'll need a different approach. This is important when using scripts (in my case, PHP build scripts) which use brew --prefix package_name to determine what directory to use for compilation.
If you are using brew extract a version is added to the end of the package name which will break the brew --prefix lookup.
Here's how to install an older package version while maintaining the original package name:
# uninstall the newer version of the package that you accidentally installed
brew uninstall --ignore-dependencies icu4c
# `extract` the version you'd like to install into a custom tap
brew tap-new $USER/local-tap
brew extract --version=68.2 icu4c $USER/local-tap
# jump into the new tap you created
cd $(brew --repository $USER/local-tap)/Formula
# rename the formula
mv icu4c#68.2.rb icu4c.rb
# change the name of the formula by removing "AT682" from the `class` definition
# the exact text you'll need to remove will be different
# depending on the version you extracted
nano icu4c.rb
# then, install this specific formula directly
brew install $(brew --repository $USER/local-tap)/Formula/icu4c.rb
I wrote more about this here.
On the newest version of homebrew (0.9.5 as of this writing) there will be a specific recipe for the version of the homebrew keg you want to install. Example:
$ brew search mongodb
mongodb mongodb24 mongodb26
Then just do brew install mongodb26 like normal.
In the case that you had already installed the latest version, make sure to unlink the latest version and link the desired version: brew unlink mongodb && brew link mongodb26.
The problem with homebrew/versions is that someone has to have that specific version of software listed in the repository for you to be able to use it. Also, since brew versions is no longer supported, another solution is required. For solutions that indicate using brew switch, this will only work if you haven't done a brew cleanup since the version needs to exist on your computer.
I had a problem with wanting to install a specific older version of docker-machine which wasn't listed in homebrew/versions. I solved this using the below, which should also work for any brew installed software. The example below will use docker-machine as the package I want to downgrade from version 0.5.0 to 0.4.1.
Go to your homebrew Formula directory.
You can determine this by running brew info [any package name].
For example, brew info docker-machine gives me a line that shows me
a path - /usr/local/Cellar/docker-machine/0.5.0. This tells me that on my machine, homebrew is installed at /usr/localand my Formula
directory is located by default at /usr/local/Library/Formula
Locate the specific formula file (.rb) for your package.
Since I want to downgrade docker-machine, I can see a docker-machine.rb file.
Get the version history for this formula file .
Enter git log docker-machine.rb. This will list out the complete commit history for this file. You will see output like this:
...more
commit 20c7abc13d2edd67c8c1d30c407bd5e31229cacc
Author: BrewTestBot
Date: Thu Nov 5 16:14:18 2015 +0000
docker-machine: update 0.5.0 bottle.
commit 8f615708184884e501bf5c16482c95eff6aea637
Author: Vincent Lesierse
Date: Tue Oct 27 22:25:30 2015 +0100
docker-machine 0.5.0
Updated docker-machine to 0.5.0
Closes #45403.
Signed-off-by: Dominyk Tiller
commit 5970e1af9b13dcbeffd281ae57c9ab90316ba423
Author: BrewTestBot
Date: Mon Sep 21 14:04:04 2015 +0100
docker-machine: update 0.4.1 bottle.
commit 18fcbd36d22fa0c19406d699308fafb44e4c8dcd
Author: BrewTestBot
Date: Sun Aug 16 09:05:56 2015 +0100
docker-machine: update 0.4.1 bottle.
...more
The tricky part is to find the latest commit for the specific version you want. In the above, I can tell the latest 0.4.1 version was committed with this commit tag : commit 5970e1af9b13dcbeffd281ae57c9ab90316ba423. The commits above this point start using version 0.5.0 (git log entries are listed from latest to earliest date).
Get a previous version of the formula file.
Using the commit tag from step #3 (you can use the first 6 chars), you can get an older version of the formula file using the following:
git checkout 5970e1 docker-machine.rb
Uninstall your current package version.
Just run the normal brew commands to uninstall the current version of your package.
Ex. brew uninstall docker-machine
Install the older package version
Now, you can just run the normal brew install command and it will install the formula that you have checkout out.
Ex. brew install docker-machine
You may need to re-link by using the brew link docker-machine if necessary.
If at any time you want to revert back to the latest version of a specific package, go into the Formula directory and issue the following commands on your formula file (.rb)
git reset HEAD docker-machine.rb
git checkout -- docker-machine.rb
Then you can brew uninstall docker-machine and brew install docker-machine to get the latest version and keep it that way going forward.
Edit: 2021, this answer is no longer functional due to the github install being deprecated. (Thanks Tim Smith for update).
Install an old brew package version (Flyway 4.2.0 example)
Find your local homebrew git dir or clone Homebrew/homebrew-core locally
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/
OR
git clone git#github.com:Homebrew/homebrew-core.git
List all available versions
git log master -- Formula/flyway.rb
Copy the commit ID for the version you want and install it directly
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/793abfa325531415184e1549836c982b39e89299/Formula/flyway.rb
I've tried most of the solutions here and they are outdated. I had to combine some ideas from here with my own work. As a result I've created a script to help me do the heavy lifting which you can find here
Usage:
brewv.sh formula_name desired_version
Currently the old ways of installing specific formula versions have been deprecated. So it seems like we have to use brew edit [formula]. E.g. say we want to install an the 62.1 version of icu4c (needed e.g. for postgresql 10.5). Then you'd have to
> brew edit icu4c
# drops you to editor
Here you'd have to alter the url, version and sha256 (perhaps also mirror) to the corresponding 62.1 strings.
url "https://ssl.icu-project.org/files/icu4c/62.1/icu4c-62_1-src.tgz"
mirror "https://github.com/unicode-org/icu/releases/download/release-62-1/icu4c-62_1-src.tgz"
version "62.1"
sha256 "3dd9868d666350dda66a6e305eecde9d479fb70b30d5b55d78a1deffb97d5aa3"
then run brew reinstall icu4c to finally download the 62.1 version.
it could be done very easy for last version of brew.
brew tap homebrew/versions
brew install subversion17 # for svn 1.7 branch instead of last available
brew install postgresql8 # for postgresql 8 (which you ask)
None of these really worked for my case (Python), so I'll add my 2 cents:
cd `brew --prefix`
git log Library/Formula/python.rb
Output looks like this:
commit 9ff2d8ca791ed1bd149fb8be063db0ed6a67a6de
Author: Dominyk Tiller <dominyktiller#gmail.com>
Date: Thu Jun 30 17:42:18 2016 +0100
python: clarify pour_bottle reason
commit cb3b29b824a264895434214e191d0d7ef4d51c85
Author: BrewTestBot <brew-test-bot#googlegroups.com>
Date: Wed Jun 29 14:18:40 2016 +0100
python: update 2.7.12 bottle.
commit 45bb1e220341894bbb7de6fd3f6df20987dc14f0
Author: Rakesh <rakkesh#users.noreply.github.com>
Date: Wed Jun 29 10:02:26 2016 +0530
python 2.7.12
Closes #2452.
Signed-off-by: Tim D. Smith <git#tim-smith.us>
commit cf5da0547cd261f79d69e7ff62fdfbd2c2d646e9
Author: BrewTestBot <brew-test-bot#googlegroups.com>
Date: Fri Jun 17 20:14:36 2016 +0100
python: update 2.7.11 bottle.
...
I want version 2.7.11 so my hash is cf5da0547cd261f79d69e7ff62fdfbd2c2d646e9 (or cf5da05 for short). Next, I check out that version and install the formula python:
git checkout cf5da05
brew install python
Finally, clean up:
git checkout master
If you can't find your version with brew search <formula>, you can also try going over the commit logs for your formula to find the version you want:
here is an example for installing an older version of nginx via brew:
ngxnx formula commit log
see nginx: update 1.6.3 bottle eba75b9a1a474b9fc4df30bd0a32637fa31ec049
From there, we can install 1.6.3 with the sha and raw git url:
brew install https://raw.githubusercontent.com/Homebrew/homebrew/eba75b9a1a474b9fc4df30bd0a32637fa31ec049/Library/Formula/nginx.rb
Here my simple answer for it - was really annoyed that there is no built in solution for that so I've built my own lazy "script". Feel free to contribute 😃👍🏻
# Please define variables
packageName=<packageName>
packageVersion=<packageVersion>
# Create a new tab
brew tap-new local/$packageName
# Extract into local tap
brew extract --version=$packageVersion $packageName local/$packageName
# Verify packages is present
brew search $packageName#
# Run brew install#version as usual
brew install local/$packageName/$packageName#$packageVersion
https://gist.github.com/ArgonQQ/cff4834dab6b254cc2140bb1454b47ef
I created a tool to ease the process prescribed in this answer.
To find a package pkg with version a.b.c, run:
$ brew-install-specific pkg#a.b.c
This will list commits on the pkg homebrew formula that mention the given version along with their GitHub urls.
Matching versions:
1. pkg: update a.b.c bottle.
https://github.com/Homebrew/homebrew-core/commit/<COMMIT-SHA>
2. pkg: release a.b.c-beta
https://github.com/Homebrew/homebrew-core/commit/<COMMIT-SHA>
3. pkg a.b.c
https://github.com/Homebrew/homebrew-core/commit/<COMMIT-SHA>
Select index:
Verify the commit from the given URL, and enter the index of the selected commit.
Select index: 2
Run:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/<COMMIT-SHA>/Formula/pkg.rb
Copy and run the given command to install.
Update on the Library/Formula/postgresql.rb line 8 to
http://ftp2.uk.postgresql.org/sites/ftp.postgresql.org/source/v8.4.6/postgresql-8.4.6.tar.bz2
And MD5 on line 9 to
fcc3daaf2292fa6bf1185ec45e512db6
Save and exit.
brew install postgres
initdb /usr/local/var/postgres
Now in this stage you might face the postgresql could not create shared memory segment error, to work around that update the /etc/sysctl.conf like this:
kern.sysv.shmall=65536
kern.sysv.shmmax=16777216
Try initdb /usr/local/var/postgres again, and it should run smooth.
To run postgresql on start
launchctl load -w /usr/local/Cellar/postgresql/8.4.6/org.postgresql.postgres.plist
Hope that helps :)
I just copied an older release of elasticsearch into the /usr/local/Cellar/elasticsearch directory.
$ mkdir /usr/local/Cellar/elasticsearch/5.4.3/bin
$ cp elasticsearch /usr/local/Cellar/elasticsearch/5.4.3/bin
$ brew switch elasticsearch 5.4.3
That's it.
Maybe it's useful for anyone.
Here is how I downgrade KOPS (which does not support versioning)
# brew has a git repo on your localhost
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git remote -v
origin https://github.com/Homebrew/homebrew-core (fetch)
origin https://github.com/Homebrew/homebrew-core (push)
# find the version of kops.rb you need
git log Formula/kops.rb
# checkout old commit
# kops: update 1.18.1 bottle.
git checkout 2f0ede7f27dfc074d5b5493894f3468f27cc73f0 -- Formula/kops.rb
brew unlink kops
brew install kops
# now we have old version installed
ls -1 /usr/local/Cellar/kops/
1.18.1
1.18.2
which kops
/usr/local/bin/kops
ls -l /usr/local/bin/kops
/usr/local/bin/kops -> ../Cellar/kops/1.18.1/bin/kops
kops version
Version 1.18.1
# revert to the newest version
brew uninstall kops
git checkout -f
brew link kops
kops version
Version 1.18.2

Resources