Search code examples
swiftrubyxcodecocoapods

How can I solve this error and install cocoapods?


In my terminal I use:

sudo gem install cocoapods

My terminal gives the error shown below. How can I solve this? I have tried a few variations and I cannot get it to work.

Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
    ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.12.2/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200518-1427-ajbhbt.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/include/ruby.h

You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.12.2 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.12.2/gem_make.out

Solution

  • We need to install Xcode's developer tools. The easiest way to do this is through terminal .

    xcode-select --install
    

    Later, if there are any write permission issues, use the below code.

    sudo gem install cocoapods -n /usr/local/bin/..
    

    P.S: -n specifies the directory where binaries are located.