How can I detect from a shell script that it is running on M1 Apple hardware?
I want to be able to run a command-line command so that I can write an if
-statement whose body will only be executed when run on a mac with an M1 processor (and at least macOS Big Sur, naturally).
Head to the menu bar and click the Apple logo. Click About This Mac. Mac computers with Intel processors will show an item labeled Processor, while Mac computers with Apple silicon will show an item labeled Chip.
To open About This Mac, choose Apple menu > About This Mac. On Mac computers with an Intel processor, About This Mac shows an item labeled Processor, followed by the name of an Intel processor. A Mac with an Intel processor is also known as an Intel-based Mac.
If you see Apple M1(or higher) in the “Chip” section, it means you're using a Mac with an Apple Silicon CPU. If you see an Intel processor in the “Processor” section, it means you're using a Mac with an Intel chip. And that's how easy it is to know if you're using a Mac with an Apple Silicon CPU or an Intel processor.
uname -m
will return arm64
as opposed to x86_64
if [[ $(uname -m) == 'arm64' ]]; then
echo M1
fi
or, as @chepner suggested
uname -p
will return arm
as opposed to i386
if [[ $(uname -p) == 'arm' ]]; then
echo M1
fi
yet another tool is arch
:
if [[ $(arch) == 'arm64' ]]; then
echo M1
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With