Skip to content

Instantly share code, notes, and snippets.

@ArgonQQ
Last active March 3, 2023 02:06
Show Gist options
  • Save ArgonQQ/cff4834dab6b254cc2140bb1454b47ef to your computer and use it in GitHub Desktop.
Save ArgonQQ/cff4834dab6b254cc2140bb1454b47ef to your computer and use it in GitHub Desktop.
Brew install specific version / Locally freeze version

Brew install specific version / Locally freeze version

# Please define variables
packageName=<packageName>
packageVersion=<packageVersion>

# Create a new tab
brew tap-new local/$packageName

# Extract into local tap
brew extract --version=$packageVersion $packageName local/$packageName

# Verify packages is present
brew search $packageName@

# Run brew install@version as usual
brew install local/$packageName/$packageName@$packageVersion
@marcellodesales
Copy link

Could this be specified in the Brewfile?

@ArgonQQ
Copy link
Author

ArgonQQ commented Oct 3, 2021

Could this be specified in the Brewfile?

Sorry - I don't understand. Could you elaborate more what you're looking for? 😅

@marcellodesales
Copy link

Problem

I know brew is not a real dependency management, or else we wouldn't be talking about this hack :) I use the Brewfile to declare dependencies and use the command bundle to retrieve the latest version that brew knows about... As you automate CI/CD, it's imperative that the dependencies management step can be used to download only the specific versions... For instance, https://gitlab.com/gitlab-com/macos-buildcloud-runners-beta/-/issues/144#notepad_spiral-brewfile-for-flutter-apps shows a Brewfile with all the dependencies that I need... As one of the requirements for automation is to pin the versions of each dependency, I was wondering if Brewfile can specify versions, but I found out that we can't...

I would guess we could write an extension, with your approach, on top of the Brewfile spec to specify versions and then we could declare them in the Brewfile spec :)

@basejump
Copy link

Nice work! like so many things, simple once someone pieces it together. Thanks.
I made it into a bash script as we have similiar needs as @marcellodesales
Have not totally flushed it out but this has worked for a couple of packages we needed olds version for

#!/usr/bin/env bash

##
# Usage:
#    ./brew_install_version.sh yq 4.16.1
#

# the brew package name, ex: yq
packageName=$1
# the older version to install
packageVersion=$2

# Create a new tab
brew tap-new local/$packageName

# Extract into local tap
brew extract --version=$packageVersion $packageName local/$packageName

# Sanity check packages is present
brew search $packageName@

# Run brew install@version as usual
brew install local/$packageName/$packageName@$packageVersion

# optional, to clean up when done
# rm -rf /usr/local/Homebrew/Library/Taps/local/homebrew-$packageName/

@ArgonQQ
Copy link
Author

ArgonQQ commented Dec 11, 2021

Hi @basejump,

I am always happy to help & share some things which really bugged me for example with brew 😎👍.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment