Skip to content

Instantly share code, notes, and snippets.

@tjluoma
Last active April 5, 2023 21:22
Find the actual arch (arm64 or i386) of a Mac, even if running in Rosetta
## 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"
@tjluoma
Copy link
Author

tjluoma commented Dec 28, 2020

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 run brew), 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.

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