26

Using the case of installing Python 2.7.9 instead of the latest 2.7.10, previously I could simply use brew versions python and see all of the versions of Python formulae by their commit SHA in brew, and then check them out to install a specific version. This is an example of brew versions python output:

$ brew versions python
Warning: brew-versions is unsupported and will be removed soon.
You should use the homebrew-versions tap instead:
  https://github.com/Homebrew/homebrew-versions
2.7.9    git checkout 667284f /usr/local/Library/Formula/python.rb
2.7.8    git checkout f26ca5c /usr/local/Library/Formula/python.rb
2.7.7    git checkout d48206e /usr/local/Library/Formula/python.rb
2.7.6    git checkout 3c64184 /usr/local/Library/Formula/python.rb
2.7.5    git checkout a04b443 /usr/local/Library/Formula/python.rb
2.7.3    git checkout 865f763 /usr/local/Library/Formula/python.rb
2.7.4    git checkout 280581d /usr/local/Library/Formula/python.rb
2.7.2    git checkout 97c6869 /usr/local/Library/Formula/python.rb
2.7.1    git checkout 83ed494 /usr/local/Library/Formula/python.rb
2.7      git checkout 1bf3552 /usr/local/Library/Formula/python.rb
2.6.5    git checkout acd49f7 /usr/local/Library/Formula/python.rb
2.6.4    git checkout 843bff9 /usr/local/Library/Formula/python.rb
2.6.3    git checkout 5c6cc64 /usr/local/Library/Formula/python.rb

But the latest version of brew has already removed versions support, and I don't understand how to install a previous Python using https://github.com/Homebrew/homebrew-versions. How do you actually install Python 2.7.9 instead of the newer 2.7.10?

I would like to know how to use homebrew-versions instead of the more trivial way brew versions.

With brew versions I could easily see all versions from that specific formulae (have a look at the above Python versions spit out by brew versions python). From the doc, there is no clear way to achieve the same result as brew versions python does.

Stanislav Pankevich
  • 9,838
  • 6
  • 60
  • 113
swdev
  • 4,367
  • 8
  • 53
  • 94
  • Is your question *"How can I use `homebrew-versions`"*? If so, have you tried using [their documentation](https://github.com/Homebrew/homebrew-versions#how-do-i-install-these-formulae)? Where exactly did you get stuck? If not, what *is* it? – jonrsharpe Sep 21 '15 at 15:36
  • I have already thought there'll be this kind of answer actually :D. Will revise the question – swdev Sep 21 '15 at 21:43
  • https://stackoverflow.com/questions/3987683/homebrew-install-specific-version-of-formula?rq=1 is a very similar question. – Tim Smith Sep 24 '15 at 03:53
  • 1st comment has a dead link. pls update – blkpingu Jul 13 '20 at 14:48

3 Answers3

35

homebrew-versions used to be the easiest way to do this, but homebrew-versions has been deprecated and is no longer available in the current version of homebrew.

To find what versions are readily available, use the following command:

brew search python

to list out all of the available python packages which would display old versions like python@2 and then you could install them by using:

brew install python@2

Some Alternative Approaches

Switching To Previous Version

If you have already installed the older version of the formula and have not removed it you can simply switch the symlinks to reference it using a brew command.

brew switch python 2.7.9

This command would switch you to version 2.7.9

brew switch python 2.7.10

This would switch you back to version 2.7.10

Formula GitHub History

If you do not still have the older version available on your system there is another method you could try but it is more difficult and almost certainly unsupported by Homebrew so if you end up with issues you may not be able to rely on their help.

https://github.com/Homebrew/homebrew-core/commits/master/Formul/<formula>.rb should take you to the commit history of that formula. For your example of installing python 2.7.9 you would do the following:

  1. Go to https://github.com/Homebrew/homebrew-core/commits/master/Formula/python.rb
  2. Look for the entry with a commit summary of "python 2.7.10"
  3. Find and copy the commit hash of the entry below it (1681e19 in this example)
  4. Input git checkout 1681e19 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/python.rb into the terminal

From this point you would do whatever you would normally do to install the older version of python with the old versions method. This appears to be all the old method was doing.

Alsy
  • 3
  • 3
  • Awesome! I have also played with git checkout. But would love to have a more "official" way to do this. I'll report once I tested this, but I have already accepted this as the answer one – swdev Sep 22 '15 at 02:23
  • How to restore the repo to it's previous state, after the checkout? `git checkout HEAD`? – LShi Feb 20 '17 at 08:17
  • As it is just a git repository, I believe that should work. Is it not working for you? – Vincent Cunningham Feb 22 '17 at 23:55
  • I am afraid that I got: "Error: homebrew/versions was deprecated" error. Too bad, it seemed like such a good way to get old versions. – r02 Apr 23 '18 at 06:04
4

Homebrew doesn't support installing formulas from git history, although it's possible. There are no python* formulas in the homebrew-versions tap because I think they would be a lot of work to maintain and don't provide the best possible user experience. pyenv is a great tool that solves a lot of the problems associated with keeping multiple pythons around. There's also a user-maintained tap with older Python versions; you could contribute a 2.7.9 formula there.

Tim Smith
  • 5,548
  • 1
  • 22
  • 30
  • I haven't tried the above answer actually. But, yes, I can't find python 2.7.9 in its history. – swdev Sep 24 '15 at 16:36
  • I have problem with pyenv actually: with PyInstaller it lead to macholib error described here: https://groups.google.com/forum/#!topic/pyinstaller/6MwQcLB4H9A It's the same with using Python2.7.9 binary coming from python.org – swdev Sep 28 '15 at 23:21
  • 1
    I used the [zoidbergwill/homebrew-python user-maintained tap](https://github.com/zoidbergwill/homebrew-python) and it worked for me. It's indeed missing the 2.7.9 formula, but it has a small guide in the readme. I had to use 3.5 instead of 3.6 :) – GabLeRoux Mar 22 '17 at 13:19
  • To specify the answer, use this: `brew install pyenv` then `pyenv install 2.7.9` or whatever version number you need. – Agile Bean Jul 14 '18 at 17:40
0

If you want install a specific python version using brew (Home brew).

Example: I am trying to install python 3.7 and current python at this time is python 3.8

brew install python@3.7 -- This will make me install python 3.7

brew install python -- This will make me install python 3.8 which is current version of python while writing this comment.