How do I install a specific version of a formula in homebrew? For example, postgresql-8.4.4 instead of the latest 9.0.
Homebrew install specific version of formula
homebrewinstallationversioning
Related Solutions
Python 2.7.9+ and 3.4+
Good news! Python 3.4 (released March 2014) and Python 2.7.9 (released December 2014) ship with Pip. This is the best feature of any Python release. It makes the community's wealth of libraries accessible to everyone. Newbies are no longer excluded from using community libraries by the prohibitive difficulty of setup. In shipping with a package manager, Python joins Ruby, Node.js, Haskell, Perl, Go—almost every other contemporary language with a majority open-source community. Thank you, Python.
If you do find that pip is not available when using Python 3.4+ or Python 2.7.9+, simply execute e.g.:
py -3 -m ensurepip
Of course, that doesn't mean Python packaging is problem solved. The experience remains frustrating. I discuss this in the Stack Overflow question Does Python have a package/module management system?.
And, alas for everyone using Python 2.7.8 or earlier (a sizable portion of the community). There's no plan to ship Pip to you. Manual instructions follow.
Python 2 ≤ 2.7.8 and Python 3 ≤ 3.3
Flying in the face of its 'batteries included' motto, Python ships without a package manager. To make matters worse, Pip was—until recently—ironically difficult to install.
Official instructions
Per https://pip.pypa.io/en/stable/installing/#do-i-need-to-install-pip:
Download get-pip.py
, being careful to save it as a .py
file rather than .txt
. Then, run it from the command prompt:
python get-pip.py
You possibly need an administrator command prompt to do this. Follow Start a Command Prompt as an Administrator (Microsoft TechNet).
This installs the pip package, which (in Windows) contains ...\Scripts\pip.exe that path must be in PATH environment variable to use pip from the command line (see the second part of 'Alternative Instructions' for adding it to your PATH,
Alternative instructions
The official documentation tells users to install Pip and each of its dependencies from source. That's tedious for the experienced and prohibitively difficult for newbies.
For our sake, Christoph Gohlke prepares Windows installers (.msi
) for popular Python packages. He builds installers for all Python versions, both 32 and 64 bit. You need to:
For me, this installed Pip at C:\Python27\Scripts\pip.exe
. Find pip.exe
on your computer, then add its folder (for example, C:\Python27\Scripts
) to your path (Start / Edit environment variables). Now you should be able to run pip
from the command line. Try installing a package:
pip install httpie
There you go (hopefully)! Solutions for common problems are given below:
Proxy problems
If you work in an office, you might be behind an HTTP proxy. If so, set the environment variables http_proxy
and https_proxy
. Most Python applications (and other free software) respect these. Example syntax:
http://proxy_url:port
http://username:password@proxy_url:port
If you're really unlucky, your proxy might be a Microsoft NTLM proxy. Free software can't cope. The only solution is to install a free software friendly proxy that forwards to the nasty proxy. http://cntlm.sourceforge.net/
Unable to find vcvarsall.bat
Python modules can be partly written in C or C++. Pip tries to compile from source. If you don't have a C/C++ compiler installed and configured, you'll see this cryptic error message.
Error: Unable to find vcvarsall.bat
You can fix that by installing a C++ compiler such as MinGW or Visual C++. Microsoft actually ships one specifically for use with Python. Or try Microsoft Visual C++ Compiler for Python 2.7.
Often though it's easier to check Christoph's site for your package.
EDIT:
It looks like the issue is now solved using an external command called brew rmdeps
or brew rmtree
.
To install and use, issue the following commands:
$ brew tap beeftornado/rmtree
$ brew rmtree <package>
See the above link for more information and discussion.
[EDIT] see the new command brew autoremove
in https://stackoverflow.com/a/66719581/160968
Original answer:
It appears that currently, there's no easy way to accomplish this.
However, I filed an issue on Homebrew's GitHub page, and somebody suggested a temporary solution until they add an exclusive command to solve this.
There's an external command called brew leaves
which prints all packages that are not dependencies of other packages.
If you do a logical and on the output of brew leaves
and brew deps <package>
, you might just get a list of the orphaned dependency packages, which you can uninstall manually afterwards. Combine this with xargs
and you'll get what you need, I guess (untested, don't count on this).
EDIT: Somebody just suggested a very similar solution, using join
instead of xargs
:
brew rm FORMULA
brew rm $(join <(brew leaves) <(brew deps FORMULA))
See the comment on the issue mentioned above for more info.
Related Topic
- Postgresql – How to start PostgreSQL server on Mac OS X
- Ruby-on-rails – Postgres could not connect to server
- Macos – How to fix homebrew permissions
- Python – How to install pip on macOS or OS X
- Bash – Installing Homebrew on OS X
- Java – How to install Java 8 on Mac
- Python: sort the list
- Postgresql – `pg_tblspc` missing after installation of latest version of OS X (Yosemite or El Capitan)
Best Answer
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
(orbrew switch postgresql <TAB>
) whether the older version is installed:We see that some older version is already installed. We may activate it using
brew switch
:Let’s double-check what is activated:
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, usingbrew 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:We can simply install it by typing
Note that this has automatically tapped the
homebrew/versions
tap. (Check withbrew tap
, remove withbrew untap homebrew/versions
.) The following would have been equivalent: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 abrew 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.
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.
Now that the older postgresql version is installed, we can re-install the latest formula in order to keep our repository clean:
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.
git log -S
looks for all commits in which the string'8.4.4'
was either added or removed in the fileLibrary/Taps/homebrew/homebrew-core/Formula/postgresql.rb
. We get two commits as a result.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):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: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: