Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Apple Silicon from command line

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).

like image 536
Klas Mellbourn Avatar asked Dec 11 '20 22:12

Klas Mellbourn


People also ask

How do I know if I have Apple silicone?

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.

How do you know if an Apple is Intel or silicon?

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.

How do I know if my Mac has M1?

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.


1 Answers

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
like image 95
Klas Mellbourn Avatar answered Oct 22 '22 11:10

Klas Mellbourn