Skip to content

Instantly share code, notes, and snippets.

@tjluoma
Last active April 5, 2023 21:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjluoma/22f26a7519162fd5aeb39bf4bf43780b to your computer and use it in GitHub Desktop.
Save tjluoma/22f26a7519162fd5aeb39bf4bf43780b to your computer and use it in GitHub Desktop.
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

An Alternative Method: I don't prefer this way, but it is another option:

sysctl kern.version | fgrep -q '/RELEASE_ARM64_'

EXIT="$?"

if [[ "$EXIT" == "0" ]]
then
	ARCH='arm64'
else
	ARCH='i386'
fi

@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