一句话总结:新Mac 不要直接用系统再带的ruby安装cocoapods,自己动手装一个ruby,然后再安装cocoapods。
RROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
如果你已经遇到这个错误了 直接重装ruby避免再走弯路
安装新的ruby,安装homebrew,使用如下命令
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
遇到报错:
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
此时需要修改hosts:
添加以下内容(到https://www.ipaddress.com/查看,raw.githubusercontent.com对应的ip地址)
99.232.28.133 raw.githubusercontent.com
修改完成,再执行安装命令:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
过程有点慢,安装Homebrew完成后查看一下版本:
brew -v
得到结果:
Homebrew 2.7.0
说明革命第一步成功了。
接着安装RVM,RVM是rubyh环境管理工具,这里使用命令:
curl -L https://get.rvm.io | bash -s stable
很好,很顺利。载入rvm环境,命令:
source ~/.rvm/scripts/rvm
再来查看一下ruby已知版本,命令:
rvm list known
根据结果,挑选一个你想安装的ruby版本,我装的2.6.6,命令:
rvm install 2.6.6
这里我遇到了问题,如果没有遇到该问题可以直接跳过下面这一步
遇到的问题 报错内容如下:
nstalling requirements for osx.
Updating system.....
Installing required packages: autoconf, automake, libtool, pkg-config, libyaml, readline, libksba, openssl|
........
Error running 'requirements_osx_brew_libs_install autoconf automake libtool pkg-config libyaml readline libksba openssl**',
showing last 15 lines of /Users/MTKJ/.rvm/log/1469285314_ruby-2.3.0/package_install_autoconf_automake_libtool_pkg-config_libyaml_readline_libksba_openssl.log
看错误提示 因为缺少autoconf automake libtool pkg-config libyaml readline libksba openssl这些库,
所以用homebrew挨个去安装这些库
brew install autoconf
brew install automake
brew install lib tool
brew install apple-gcc42
brew install libyaml
brew install libxslt
brew install libksba
brew install openssl
可能你的电脑缺少的库跟我的不一样,按照日志提示的去安装就好了
最后,都安装好后,再执行rvm install 2.6.6
如果没有上面问题,只是过程也有点慢,其余也很顺利的话,说明离革命胜利已经不远了。关掉终端,重开查一下ruby的版本,命令:
ruby -v
看一下是不是刚刚下载的版本 如果不是执行
rvm use ruby-2.6.6
然后执行
sudo gem install cocoapods
更新下载cocoapods
此时又需要一波等待,完成后查看版本:
pod --version
成功返回版本号:
1.11.2
至此,踩坑结束,安装完成。后面不用再看,贴一下报错信息,便于搜索而已
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.14.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 ./siteconf20201226-5110-w2ijvp.rb extconf.rb
checking for ffi.h... *** 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
--without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
--with-ffi_c-dir
--without-ffi_c-dir
--with-ffi_c-include
--without-ffi_c-include=${ffi_c-dir}/include
--with-ffi_c-lib
--without-ffi_c-lib=${ffi_c-dir}/lib
--enable-system-libffi
--disable-system-libffi
--with-libffi-config
--without-libffi-config
--with-pkg-config
--without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
from extconf.rb:10:in `system_libffi_usable?'
from extconf.rb:42:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.14.2/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.14.2/gem_make.out
网友评论