最近刚升级了macOS Big Sur,第二天接手了一个完成度90%的iOS项目。代码下载之后,关于CocoaPod部分完全不对。经过一番折腾,卸载了本mac上的CocoaPod,可是再装的时候就遇到了问题。只能继续折腾。
Ruby环境
CocoaPods是一个用Ruby写的、负责管理iOS项目中第三方开源库的工具。Mac电脑自带Ruby环境,可以打开终端先看一下版本:ruby -v
hello:~ zxs$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
看版本是2.6.3,是2019年4月16日的版本,现在是2020年12月,1年多前的版本,不算高也不算低,可以先用着试试。
检查Ruby镜像源
一般要求是ruby-china比较好,这是Ruby在国内的镜像,速度相对国外的要快一些。
hello:~ zxs$ gem sources -l
Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2
*** CURRENT SOURCES ***
https://gems.ruby-china.com
镜像源没问题,这个以前就更换过。可是这次多出了这些是什么鬼?Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2
安装CocoaPod不成功
hello:~ zxs$ sudo gem install -n /usr/local/bin cocoapods
Password:
Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2
又出现这个鬼:Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2
长时间卡在这里了,怎么办?
- 直接
Control + C
强行退出是可以的,可是CocoaPod
没装上啊- 后来解决了
Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2
,采用sudo gem install -n /usr/local/bin cocoapods
仍然是长时间没有反应,需要Control + C
强行退出
虽然这次由于等的时间长,最后
Control + C
强行退出了,但是安装的命令其实没错。是网络问题,还是上面那个Ruby异常影响的,谁也说不清楚。
解决Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2
提示里面已经有,就是gem pristine ffi --version 1.12.2
,只是由于权限问题,前面要加sudo
hello:~ zxs$ sudo gem pristine ffi --version 1.12.2
Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2
Restoring gems to pristine condition...
Building native extensions. This could take a while...
Restored ffi-1.12.2
gem pristine --all
实际试过,这个直接用是没有效果的;
- 升级Gem到最新:
hello:~ zxs$ sudo gem update --system
Updating rubygems-update
Fetching rubygems-update-3.2.3.gem
Successfully installed rubygems-update-3.2.3
Parsing documentation for rubygems-update-3.2.3
Installing ri documentation for rubygems-update-3.2.3
Installing darkfish documentation for rubygems-update-3.2.3
Done installing documentation for rubygems-update after 87 seconds
Parsing documentation for rubygems-update-3.2.3
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 3.2.3
检查一下版本号:
hello:~ zxs$ gem -v
3.2.3
权限问题
到CocoaPod的官网,推荐的命令很简单:
照这个命令做,会遇到权限问题:
hello:~ zxs$ sudo gem install cocoapods
Password:
Fetching cocoapods-1.10.0.gem
Fetching nanaimo-0.3.0.gem
Fetching xcodeproj-1.19.0.gem
Fetching cocoapods-downloader-1.4.0.gem
Fetching public_suffix-4.0.6.gem
Fetching addressable-2.7.0.gem
Fetching activesupport-5.2.4.4.gem
Fetching cocoapods-core-1.10.0.gem
Successfully installed nanaimo-0.3.0
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory.
这句话直接说明了这样做缺少访问权限。那怎么办?
再次尝试
直接ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory.
百度,找到了一篇文章,解释得非常清楚:
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /
- 这里提到的安装(解决权限问题)命令
sudo gem install -n /usr/local/bin cocoapods
和前面试过的一模一样。再试一次,也还会卡一段较长时间,多等一会。这次尝试算是成功了:
hello:~ zxs$ sudo gem install -n /usr/local/bin cocoapods
Password:
Successfully installed xcodeproj-1.19.0
Successfully installed cocoapods-downloader-1.4.0
Successfully installed public_suffix-4.0.6
Successfully installed addressable-2.7.0
Successfully installed activesupport-5.2.4.4
Successfully installed cocoapods-core-1.10.0
Successfully installed cocoapods-1.10.0
Parsing documentation for xcodeproj-1.19.0
Installing ri documentation for xcodeproj-1.19.0
Parsing documentation for cocoapods-downloader-1.4.0
Installing ri documentation for cocoapods-downloader-1.4.0
Parsing documentation for public_suffix-4.0.6
Installing ri documentation for public_suffix-4.0.6
Parsing documentation for addressable-2.7.0
Installing ri documentation for addressable-2.7.0
Parsing documentation for activesupport-5.2.4.4
Installing ri documentation for activesupport-5.2.4.4
Parsing documentation for cocoapods-core-1.10.0
Installing ri documentation for cocoapods-core-1.10.0
Parsing documentation for cocoapods-1.10.0
Installing ri documentation for cocoapods-1.10.0
Done installing documentation for xcodeproj, cocoapods-downloader, public_suffix, addressable, activesupport, cocoapods-core, cocoapods after 7 seconds
7 gems installed
- 通过查看pod版本号的方式验证一下是否安装成功:
hello:~ zxs$ pod --version
1.10.0
- 其他的检查命令也可以试一下,至少验证CocoaPod本身是正常的
hello:~ zxs$ pod setup
Setup completed
hello:~ zxs$ pod repo list
master
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/zxs/.cocoapods/repos/master
trunk
- Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/zxs/.cocoapods/repos/trunk
查找著名的AFNetworking
小结
Mac操作系统升级到当前时间点最新的
v11.1 macOS Big Sur
,会导致自带的Ruby系统抛出异常:Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2
采用提示信息可以解决这个小问题(也不一定是问题),只是会遇到权限问题,需要在命令前加个
sudo
;执行一下:sudo gem pristine ffi --version 1.12.2
这个烦人的异常提示就没有了。v11.1 macOS Big Sur
自带的Ruby(版本2.6.3)可用,Ruby Gem正常可用;以前切换的Ruby镜像源https://gems.ruby-china.com/
也仍然可用;CocoaPod也能正常安装,基本功能正常。