How to Install Specific Version of Brew Cask
Brew Cask is an extension of Homebrew that allows us to install GUI tools or 3rd party binaries easily just by using command line.
It is so convenient and I have been using it to install most of my app like Chrome, Android Studio or VSCode for years. One of the app I used regularly is Periphery, which is a tool for identifying unused codes in iOS projects.
Recently, I ran brew upgrade
and unfortunately the update caused Periphery app to stop working. The latest version(2.15.0) requires Swift 5.7 but I’m still using Xcode 14.1. I thought I could just run brew install periphery@2.14.0
to downgrade the version but it did not work.
Did some googling but the steps aren’t straightforward so I will document it down here for my future self.
So here’s the steps:
- Google the casks that you want to install the specific version of here. If it’s not part of brew, search it on Github. For example here’s the page for periphery
- Go through the commits history. Find the version that you want and the cask file
- Copy the URL of the raw file
- Run
brew install --cask [RAW_FILE_URL]
. For example if I want to installperiphery@2.14.0
I need to run the following command:brew install --cask https://raw.githubusercontent.com/peripheryapp/homebrew-periphery/6f8d7a080fc41e336ec6f1dca9039117a7886875/Casks/periphery.rb
Other Ways to Install
There’s another way to install by using brew edit
.
Here’s the steps:
Run
brew edit [APP_NAME]
. Note that running this for the first time will trigger the following warning message since you will be editing the Cask file directlyWarning: edit is a developer command, so Homebrew's developer mode has been automatically turned on. To turn developer mode off, run: brew developer off
Update the version and
sha256
value based on the version that you want to install. You can find the info on Github. Using the same example:cask 'periphery' do - version '2.15.0' - sha256 '7f0d05c7e9d04925f8c8ed4365146c23abd3b4ac1a5865f125438ce9851f93f7' + version '2.14.0' + sha256 'f44af8004706416610709ed4f913cedc06e458941a6968c095c475bef54e1920' url "https://github.com/peripheryapp/periphery/releases/download/#{version}/periphery-#{version}.zip" name 'Periphery' homepage 'https://github.com/peripheryapp/periphery' binary 'periphery' depends_on macos: '>= :catalina' ``` zap delete: [ '~/Library/Caches/com.github.peripheryapp', '~/Library/Caches/com.peripheryapp.periphery' ] end
Save it and simply run
brew reinstall [APP_NAME]
.
That’s all. Hope this helps.