Use Homebrew Cask to downgrade or install specific version of package

Nov 5, 2016 Mac 中文版

Homebrew Cask, built on top of Homebrew, is an excellent package manager running on Mac OS. But, it could be a little bit tricky if you want to downgrade or install specific version of package. So, this article is about how to do it by using Homebrew Cask, and I will take installing VirtualBox as an example.



Cask file

A Cask file (or called Formula) is an Ruby script that Homebrew Cask utilizes it to compile or install a package. Usually, you can find Cask files in /usr/local/Library/Taps/caskroom/homebrew-cask/Casks/ (or /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask/Casks/). Each package (software) has its own Cask file, so you can customize it to meet your needs. To edit:

# List installed packages
brew cask list

# Edit Cask file
brew cask edit <PackageName>

# e.g. Edit VirtualBox Cask file
brew cask edit virtualbox

The command might not work if you already removed the package. In this case, you have to open the Cask file by yourself.

Modify the Cask file

Now, we are going to specify the version of package by modifying the Cask file. All we have to do is to change the values of the version and the sha256. Take a look at the latest Cask file (still take VirtualBox as an example):

# The latest version of Virtualbox (5.1.8)
cask 'virtualbox' do
  if MacOS.version <= :lion

  ... skip some content

  else
    version '5.1.8-111374'
    sha256 '2eae6eadcf2a5532979a46eb007820f8c4205bf4de1e070a4c3543e4d56e335f'
  end

  url "http://download.virtualbox.org/virtualbox/#{version.sub(%r{-.*}, '')}/VirtualBox-#{version}-OSX.dmg"
  appcast 'http://download.virtualbox.org/virtualbox/LATEST.TXT',
          checkpoint: '280bd9701a0fcbe1d7ef2e23ffede42d31db69bedaeb7b46084e450e653d8224'

  ... skip some content

Below is a modified example:

# Change version from 5.1.8 to 5.0.20 
cask 'virtualbox' do
  if MacOS.version <= :lion

  ... skip some content

  else
    version '5.0.20-106931'
    sha256 '804bfe75d40baf1a25ba025a07f440165868947ad2b41164ab0105cfa0fe6936'
  end

  url "http://download.virtualbox.org/virtualbox/#{version.sub(%r{-.*}, '')}/VirtualBox-#{version}-OSX.dmg"
  appcast 'http://download.virtualbox.org/virtualbox/LATEST.TXT',
          checkpoint: '804bfe75d40baf1a25ba025a07f440165868947ad2b41164ab0105cfa0fe6936'

  ... skip some content


Reinstall the package

Once modified the Cask file, let’s reinstall the package:

# Reinstall a package
brew cask uninstall --force <PackageName>; brew cask install <PackageName>;

# Reinstall the VirtualBox
brew cask uninstall --force virtualbox; brew cask install virtualbox;



You might also like:




If you have any suggestions, questions or even find some typos, feel free to contact me. Thank you! :)

zeckli.devforgalaxy@gmail.com   © 2015-2019 zeckli, thanks to Jekyll and GitHub.