Search code examples
homebrewhomebrew-cask

Brew List and Install Specific Versions of Formula


I would like to install 2.6.X but cannot find documentation on how to specify a formula version. Brew is only installing the latest version of the formula.

I'm using the following versions of brew

Homebrew 1.8.6
Homebrew/homebrew-core (git revision 5ea559; last commit 2018-12-18)
Homebrew/homebrew-cask (git revision 4144b74; last commit 2018-12-18)

I'm upgrading from 2.2.1 and want to be pinned to 2.6.X

ls /usr/local/Cellar/ansible
2.2.1.0_2   2.3.1.0     2.7.5

brew search ansible
==> Formulae
ansible ✔                                 ansible-cmdb                              
ansible-lint                              [email protected]                               
[email protected]                               terraform-provisioner-ansible 
==> Casks
ansible-dk

brew install ansible

ansible --version
ansible 2.7.5

If someone could point me to the correct docs at https://docs.brew.sh/ to both list all available versions and to install specific versions that would be awesome.


Solution

  • Go to the directory containing formulas:

    cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
    

    Look at the history of the ansible formula

    git log -- ansible.rb
    

    Select the commit where the version you are interested in is and checkout this formula:

    git checkout f9466d14ee6e9fa7a -- ansible.rb
    

    Install that formula:

    HOMEBREW_NO_AUTO_UPDATE=1 brew install ansible
    

    Check the installation of ansible:

    ansible --version
    

    Pin this version of the formula to avoid upgrade

    brew pin ansible
    

    That's it, an I'm not sure that this is in the documentation.