Last active
September 23, 2021 16:15
-
-
Save josephschmitt/ae8cab59024b72c1985e4bcf28f9eeb5 to your computer and use it in GitHub Desktop.
Function to update the PATH to point to the "correct" brew installation depending on architecture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This function is for use on Macs with multiple brew installations (usually M1/arm64) Macs. This | |
# function will attempt to set your brew PATH to point to the correct brew based on the system arch. | |
# | |
# Usage: | |
# # will automatically set brew based on architecture | |
# $ switch_brew | |
# | |
# # will set brew for arm64 | |
# $ switch_brew arm64 | |
# | |
# # will set brew for x86_64 | |
# $ switch_brew x86_64 | |
function switch_brew { | |
armBrewPath="/opt/homebrew/bin" | |
switch_to=${1:-"$(uname -m)"} | |
if [ "${switch_to}" = "arm64" ]; then | |
PATH="${armBrewPath}:$PATH" | |
else | |
PATH=${PATH/":$armBrewPath"/} # delete any instances in the middle or at the end | |
PATH=${PATH/"$armBrewPath:"/} # delete any instances at the beginning | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function should be added to your
~/.bashrc
or~/.zshrc
(depending on which shell you use).See homebrew's installation instructions for more context, or this explanation.
Additionally, this blog post goes into more explanation on the multi-brew setup.