Last active
April 5, 2023 21:22
Find the actual arch (arm64 or i386) of a Mac, even if running in Rosetta
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
## Note - this should work in bash and zsh scripts | |
ARCH=$(sysctl kern.version | awk -F'_' '/RELEASE/{print $2}') | |
if [[ "$ARCH" == "ARM64" ]] | |
then | |
ARCH='arm64' | |
elif [[ "$ARCH" == "X86" ]] | |
then | |
ARCH='i386' | |
else | |
echo "Unknown arch returned: '$ARCH'" >>/dev/stderr | |
exit 2 | |
fi | |
echo "$ARCH" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What problem is this trying to solve: Normally you would use the
arch
command to tell if your Mac is 'i386' or 'arm64'. However, your script (or even your Terminal.app) might be running under Rosetta (for example, as of 2020-12-28 that is the recommended way to runbrew
), which would make it appear that you are on i386 even when you are on 'arm64'.When trying to download Mac apps that offer separate versions for Intel or ARM (M1/Apple Silicon), you probably want the ARM version, even if your terminal program is running under Rosetta.