Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active June 15, 2020 09:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/cbbbb95b571bd08bb5aa to your computer and use it in GitHub Desktop.
Save Integralist/cbbbb95b571bd08bb5aa to your computer and use it in GitHub Desktop.
[Brew switch to custom versions of software] #homebrew #brew #install #versions #switch

If you wish to switch your python command to use a different Python interpreter (and it's a Python version you previously had installed using Homebrew):

brew info python           # To see what you have previously installed
brew switch python 3.x.x_x # Ex. 3.6.5_1

NOTE: this might not be wise to do as you might have other software that relies on the Python interpreter you have currently (i.e. before the switch).

Otherwise to install multiple Python versions using Homebrew (instead of something like pyenv)...

Template:

brew install https://address/to/the/formula/FORMULA_NAME.rb

Example Python 3 template:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/COMMIT_IDENTIFIER/Formula/python.rb

Now you can't view the commits via the GitHub UI because there are so many, so you'll have to clone the homebrew-core repository and do it via the command line:

git clone git@github.com:Homebrew/homebrew-core.git
git log master -- Formula/python.rb

From there you can search for the commits which update the Python version by searching for the message python: update <version> bottle.

Example: we want to install Python version 3.7.5

git log --oneline --grep '^python: update .\+ bottle'

c14db427e7 python: update 3.7.7 bottle.
f02346bd48 python: update 3.7.6_1 bottle.
7ef074a882 python: update 3.7.6 bottle.
2efdfe5519 python: update 3.7.5 bottle.    # << HERE IT IS!
6589f0f6f5 python: update 3.7.4_1 bottle.
e9004bd764 python: update 3.7.4_1 bottle.
1c2239bfdf python: update 3.7.4_1 bottle.
48aba7218e python: update 3.7.4 bottle.
c24d6bcd47 python: update 3.7.3 bottle.
22c80fc362 python: update 3.7.3 bottle.

...etc

Now we know the commit hash for the Python version 3.7.5 (i.e. 2efdfe5519) we want we can install that version like so:

brew unlink python # ONLY if you have installed (with brew) another version of python 3
brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/2efdfe5519/Formula/python.rb
  • brew versions {package}
  • brew switch {package} {version}

OR

  • brew uninstall {package}
  • brew versions {package}
  • git checkout {commit} Library/Formula/{package}.rb
  • brew install {package}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment