我试图将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

当前回答

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"

其他回答

如果你没有Homebrew,请先安装:https://brew.sh/index_pt-br

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

其次,如果你没有ruby,安装它: https://www.ruby-lang.org/pt/documentation/installation/

brew install ruby

你也可以按照这些步骤:https://gist.github.com/monicao/d372716cdfbb7e9cf692

然后,关闭终端,重新打开。

始终使用sudo安装cocoapods:

sudo gem install 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

首先,检查您正在使用的Ruby版本。

$ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
$ which ruby
usr/bin/ruby

现在使用Homebrew安装最新的Ruby。

$ brew install ruby
==> ruby
By default, binaries installed by gem will be placed into:
/usr/local/lib/ruby/gems/2.7.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

如果你需要在PATH运行中先使用ruby:

$ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/xxx/.bash_profile

为了让编译器找到ruby,你可能需要设置:

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

按照说明设置PATH。现在您将看到已安装的Ruby。确保将“xxx”替换为您的用户名。

$ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/xxx/.bash_profile
$ echo 'export LDFLAGS="-L/usr/local/opt/ruby/lib"' >> ~/.bash_profile
$ echo 'export CPPFLAGS="-I/usr/local/opt/ruby/include"' >> ~/.bash_profile

$ source ~/.bash_profile

最后,确保PATH已经就位。

$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
$ which ruby
/usr/local/opt/ruby/bin/ruby

你可以开始了!确保按照如下方式指定保存目的地进行安装。

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

这个命令帮了我大忙

Sudo gem install -n /usr/local/bin cocoapods -v 1.8.4

待确认检查吊舱版本

豆荚,版本

同样的错误对我来说,由于旧版本的ruby:

 ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]

以下工作为我(macOS 11.5.2大苏尔):

安装GPG密钥

curl -sSL https://rvm.io/mpapis.asc | gpg --import -
curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -
curl -sSL https://rvm.io/mpapis.asc | gpg --import -

安装NVM(并使用NVM安装新版本ruby)

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

安装版本如下:

 nvm --version
0.30.1

 ruby --version
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]

 which ruby
/Users/crifan/.rvm/rubies/ruby-3.0.0/bin/ruby

 gem --version
3.2.3

使用gem安装cocoapods

sudo gem install cocoapods

安装的版本:

 which pod
/Users/crifan/.rvm/rubies/ruby-3.0.0/bin/pod
 pod --version
1.11.3

请注意

使用自制软件安装cocoapods

酿造安装椰荚

对我来说是可以的,但版本相对较旧:

~  pod --version
1.10.1

而这里因为开发需要最新版本的cocoadpod,所以需要使用gem来安装最新的cocoadpod。