我试图将cocoapods安装到运行OSX 10.9.1(新Mavericks)的MacBook Pro上,键入gem install cocoapods后,我得到以下错误:

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

        "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby" -rubygems /usr/local/rvm/gems/ruby-1.9.3-p194/gems/rake-10.1.1/bin/rake RUBYARCHDIR=/Users/rangreenberg/gems/gems/xcodeproj-0.14.1/ext RUBYLIBDIR=/Users/rangreenberg/gems/gems/xcodeproj-0.14.1/ext
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for -std=c99 option to compiler... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `block in try_compile'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:443:in `with_werror'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `try_compile'
    from extconf.rb:24:in `block in <main>'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from extconf.rb:23:in `<main>'
rake aborted!
Command failed with status (1): [/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/...]

Tasks: TOP => default => ext
(See full trace by running task with --trace)


Gem files will remain installed in /Users/rangreenberg/gems/gems/xcodeproj-0.14.1 for inspection.
Results logged to /Users/rangreenberg/gems/gems/xcodeproj-0.14.1/ext/xcodeproj/gem_make.out

当前回答

安装命令行工具必须使用“终端”中的命令:

xcode-select --install

如果您收到“无法安装该软件,因为它目前无法从软件更新服务器获得”的消息,您必须从Apple网站手动下载命令行工具。

其他回答

执行以下命令

 brew cleanup -d -v 

然后运行以下命令

brew install cocoapods 

注意:如果你看到链接失败,那么运行brew link cocoapods

如果链接失败,则运行

酿造链接——覆盖cocoapods

这就是我解决问题的方法

对于拥有m1芯片系统的人来说,他们需要通过罗塞塔运行这个

选择“终端”并按cmd(⌘)+I,并检查“使用Rosetta打开”选项。(适用于基于m1芯片的mac)

在2020年为我工作(Mac OS Catalina)

xcode-select --install

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

错误:错误安装cocoapods:错误:未能建立gem本地扩展

首先安装Ruby版本管理器rvm:

curl -L https://get.rvm.io | bash -s stable

然后使用

source ~/.rvm/scripts/rvm 

然后安装最新版本的ruby:

rvm install ruby-2.7.2

然后流这个(你的终端)输出。

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/nec/.zprofile 

然后使用

eval "$(/opt/homebrew/bin/brew shellenv)"

最后再次尝试安装cocoapods:

sudo gem install cocoapods

以前的解决方案对我都没用。

我的情况是一个新的干净安装的macOS Catalina + XCODE;

碰巧在安装可可豆之前,我必须首先运行Xcode(在第一次运行中,Xcode设置机器与工具);

在那之后,可可豆荚就正常了。

brew reinstall ruby

将以下内容添加到您的路径中

export PATH="/usr/local/opt/ruby/bin:$PATH"

如果需要,添加这些标志。

export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"