Reputation: 2325
How do I install a specific version of a homebrew cask formula with ansible? For example, vagrant 2.2.6 whereas latest available is 2.2.7.
Upvotes: 3
Views: 6111
Reputation: 17624
EDIT: This answer is for older versions of brew
that supported the cask
sub-command, before it was removed in newer versions of brew
. Left here for archival purposes.
$ brew cask install https://raw.githubusercontent.com/Homebrew/homebrew-cask/<git-hash>/Casks/<cask-ruby-file>.rb
/TL;DR
Unlike homebrew
, casks are not versioned with @#.#.#. Instead, you must find the exact git commit hash to install from, in addition to the file name of the cask itself to run, and pass in an URL.
For example, to install ChefDK:
/Casks/chefdk.rb
) and type a version. E.g. "chefdk 2.5.3" in the search fieldhttps://raw.githubusercontent.com/Homebrew/homebrew-cask/<git-hash>/Casks/<cask-ruby-file>.rb
So we need fill in the gaps with the git hash
and cast-ruby-file
:
brew cask install https://raw.githubusercontent.com/Homebrew/homebrew-cask/be76032ad4fd5b03036ebe3628a6294354017906/Casks/chefdk.rb
It's not fun, but it's the only way...
Upvotes: 4
Reputation: 11
1.To create a tap that could store the set which has the formula of specific version.
brew tap-new [tap name]/local
2.To extract the formula of specific version.
brew extract --force --version=[version] [formula name] [tap name]/local
3.If previous step is success, you can directly install it.
brew install [formula name]@[version]
And you could use my tool.
bash <(curl -s -S -L https://raw.githubusercontent.com/2016321/Formula-Founder/main/install_specific_version_formula.sh) [formula name] [version] [specific tap, defaut is homebrew/cask]
4.But sometime you could not extract the formula what you want. You should use git. Actually, the tap is a git repository.
4_1.To found the correct tap which has the formula what you want. For example, I want to install the 2.18.0 version of xcodegen. Xcodegen is in homebrew-core.
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
4_2.To check the correct hash with regard to xcodegen.
git log xcodegen
git checkout 421359f4b3d6e8048e8660396d2fc6afb8557815
4_3.To install the 2.18.0 version of xcodegen. And you should stop(control + c) when the brew is updating automatically.
brew install xcodegen
4_4.You needn't checkout master in the brew's tap, because brew will automatically update if you hasn't set [HOMEBREW_NO_AUTO_UPDATE=true] in envionment variables when you install a new formula next time.
Upvotes: 1
Reputation: 263
With newer versions of Homebrew the cask
command has been removed and results in an error Error: Unknown command: cask
.
I was able to install a specific version on Homebrew 3.1.12
with these steps:
Follow the steps from https://stackoverflow.com/a/61552727/3302668 to find the .rb
file for your package
Download the file locally with: curl -O -L https://raw.githubusercontent.com/Homebrew/homebrew-cask/<commit>/Casks/<package>.rb
(note: YMMV depending on curl
version).
Ex:curl -O -L https://raw.githubusercontent.com/Homebrew/homebrew-cask/d81815ea27a778a312fa0e2bbef0d78f9767f45b/Casks/vagrant.rb
brew install --cask <package>.rb
Ex:brew install --cask vagrant.rb
I followed these steps to downgrade vagrant from 2.2.16 to vagrant 2.2.15, on macOS 11.4
Upvotes: 5
Reputation: 2325
I have found this solution:
---
- hosts: all
tasks:
- name: Task 1 - Check vagrant 2.2.6 is installed
stat: path=/usr/local/Caskroom/vagrant/2.2.6
register: vagrant_installed
- name: Task 2 - Install vagrant 2.2.6 if not yet installed
block:
- name: Create temporary directory to download vagrant formula
tempfile:
state: directory
register: tempdir_vagrant_rb
- name: Download formula vagrant.rb version 2.2.6
get_url:
url: https://raw.githubusercontent.com/Homebrew/homebrew-cask/ae2a540ffee555491ccbb2cefa4296c76355ef9f/Casks/vagrant.rb
dest: "{{ tempdir_vagrant_rb.path }}/vagrant.rb"
- name: Install vagrant 2.2.6
command: brew cask install {{ tempdir_vagrant_rb.path }}/vagrant.rb
First task checks if vagrant 2.2.6 is already installed by going to default cask directory. It's required to keep playbook idempotent.
Second task installs vagrant 2.2.6 using direct raw URL to the formula version 2.2.6. To find the URL, I have used this step-by-step documentation.
Upvotes: 1