简体   繁体   中英

zsh: bad CPU type in executable: kubectl (macOS Big Sur)

I am trying to install Kubernetes in Mac. I followed these instructions - https://kubernetes.io/docs/tasks/tools/install-kubectl/ (for MacOs)

Followed all the 5 steps mentioned in that link

1. curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"

2.curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl.sha256"

echo "$(<kubectl.sha256)  kubectl" | shasum -a 256 --check 

output: kubectl: OK

3. chmod +x ./kubectl

4. sudo mv ./kubectl /usr/local/bin/kubectl && \
sudo chown root: /usr/local/bin/kubectl

5. kubectl version --client

Apparently, when I executed this kubectl version --client

zsh: bad CPU type in executable: kubectl

I tried to switch the shell from zsh to sh, bash but nothing helped

Your are trying to download a version of kubectl for the darmin/amd64 architecture. "Darwin" means, effectively, MacOS, and amd64 refers to Intel and AMD 64-bit processors.

You have an M1 Mac, which famously is built around an ARM processor , unlike the rest of Apple's machines.

You would need to find kubectl built for darwin/arm64 . As @DavidMaze suggested, you may be able to obtain that by installing the kubernetes-cli package via Homebrew .

I also got the same problem. Resolved by following steps:

  • rm /usr/local/bin/kubectl
  • brew install kubectl

Now check command:

  • kubectl version --client
    you will get output something like this:

Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2", GitCommit:"092fbfbf53427de67cac1e9fa54aaa09a28371d7", GitTreeState:"clean", BuildDate:"2021-06-16T12:52:14Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"darwin/amd64"}

For Mac M1 - install Rosetta softwareupdate --install-rosetta

Working on my M1 Big Sur 11.5.1

For more info, have a look on this link Rosetta

Check this answer

The problem can have two reasons: 1- you either have a mac book with an apple silicon processor which is not supported by the app you start ( https://support.apple.com/en-gb/HT211814 ) 2- you start a i386 executable in a 64bit operating system

Solution :
1- you should install rosetta that makes this integration
2- you should check if the app is really developed for a i386 system or not. If so install the 64bit version

For me the problem was the 32bit / 64bit mismatch. To see if the app you are starting has a i386 or not you can run:

find `echo $PATH | tr ":" "\n"` -perm +1111 -exec file {} \; | grep i386

installing the 64bit version solved my issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM