Error: Command PhaseScriptExecution failed with a nonzero exit code

Hi guys,

I started using a new MacBook and I keep getting this error. So far, most people from StackOverflow suggested deleting:

  1. Podfile.lock
  2. Pods folder
  3. .xcworkspace
    and then do pod install. However, whenever I do the sudo gem install cocoapods I get this error on my terminal.

I also tried playing with the keychain access but still no luck.
Any ideas on how I can fix this?
Thanks in advance! :))

First, what is it you’re trying to do??

@km0412

You may find that it might be as simple as cleaning the build folder - Shift + Command + K
and then do a Build - Command + B

I’m just tryna run my project on a simulator

I did this but neither did it work for me :confused:

@km0412

Do you have a Mac that is equipped with an M1 chip?

yes I do

@km0412

Instead of installing cocoapods on your Mac, which needs to be done differently on an M1 chipped machine, it is much easier to add third party frameworks, like Firebase, by using Xcode’s built in Swift Package Manager.

It’s simpler and faster. Here is a link to a video from Chris Ching that explains how to do that.

1 Like

Hi Chris,

So I followed this tutorial step by step. However, after adding the file .plist file and the package, it still gives this error.

Have you deleted Derived Data?
I could do that, clean the project, and then try to build again

here is the fix: PhaseScriptExecution failed with a nonzero exit code — XCode | by Nandhakumar Srinivasan | Medium

That might be a solution in a specific case but generally cleaning the Build Folder and/or deleting the DerivedData for that project helps in most cases.