更新Mac系统后 cocoapods升级问题 2020-04-23

正文

由于需要最新版本的Xcode工具,就升级了电脑系统到10.15.4 (19E287)。安装了最新Xcode11.4安装后发现 cocoapods使用出现异常。需要重新安装cocoapods.

安装

因为Mac电脑自带Ruby环境,我们就只需打开终端直接安装就可以了。如果出现ruby版本过低的情况可以先更新ruby。

1.查看当前ruby版本

ruby -v

2.升级ruby环境(升级ruby需要借助rvm,需要先安装rvm)

1.curl -L  https://get.rvm.io | bash -s stable
2.source ~/.rvm/scripts/rvm
3.rvm -v

如果要升级rvm使用命令

rvm get stable

3.安装ruby

1.rvm list known

结果为

# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.6]
[ruby-]2.5[.5]
[ruby-]2.6[.3]
[ruby-]2.7[.0-preview1]
ruby-head

此时可以根据自己的需要安装指定版本的ruby。

rvm install 2.6.3

本文相关操作是在ruby[ruby-]2.6[.3]完成的。

4.更换镜像源(如果已经处理可忽略此步骤)

sudo gem update --system

gem sources --remove https://rubygems.org/

gem sources --add https://gems.ruby-china.com/

查看更换结果

gem sources -l
*** CURRENT SOURCES ***

https://gems.ruby-china.com

5.安装cocoapods 10.11后命令 之前的命令为(sudo gem install cocoapods)

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

此时如果出现以下错误,原因是因为在安装xcode的时候保留了之前的版本,当前系统上有两个版本的xcode.

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

    current directory: /Users/gigaiot-sasai/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/ffi-1.12.2/ext/ffi_c
/Users/gigaiot-sasai/.rvm/rubies/ruby-2.6.3/bin/ruby -I /Users/gigaiot-sasai/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0 -r ./siteconf20200423-788-10f5isy.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.

处理步骤
5.1 把最近安装的xocde拖到中,注意名称要为xcode默认名。


image.png

5.2 终端执行命令

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

5.3 再次执行安装命令

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

安装中...

Building native extensions. This could take a while...
Successfully installed ffi-1.12.2
Successfully installed ethon-0.12.0
Successfully installed typhoeus-1.3.1
Successfully installed cocoapods-core-1.9.1
Successfully installed xcodeproj-1.16.0
Successfully installed cocoapods-1.9.1
Parsing documentation for ffi-1.12.2
Installing ri documentation for ffi-1.12.2
Parsing documentation for ethon-0.12.0
Installing ri documentation for ethon-0.12.0
Parsing documentation for typhoeus-1.3.1
...

此时等待命令执行完毕就可以了。

完成后搜索测试出现以下错误。


image.png

终端执行命令 即可

pod repo remove trunk
image.png

此时就可以正常搜索查询检索了。

总结:

1.本文的场景是升级mac系统.
2.安装并保留了多个xcode.
3.pod search xx 命令长时间卡住没有正确返回.

卸载cocopods 传送门

你可能感兴趣的:(更新Mac系统后 cocoapods升级问题 2020-04-23)