2021-4-26 记安装CocoaPods最大的一次翻车事故
新电脑。。。 系统:macOS Catalina 10.15.5
1. 安装 Homebrew 的各种花式报错
- ping 不通 github.com
解决方案:进入 hosts 文件中添加 ip
Mac ~ % sudo nano /private/etc/hosts
# 下面是需要添加的内容。需要通过 https://www.ipaddress.com/ 查询域名对应的 ip,科学上网哈
199.232.69.194 github.global.ssl.fastly.net
140.82.112.4 github.com
- 执行
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
报错
报错内容大概如下:
fatal: unable to access 'https://github.com/Homebrew/brew/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
解决方案:
# 将https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh 文件在浏览器打开后全部拷贝
$ vim install.sh
# 这里会打开编辑页,进入编辑模式,粘贴内容,保存退出
$ /bin/bash install.sh
2. 安装 CocoaPods 的报错
$ sudo gem install -n /usr/local/bin cocoapods
Password:
Building native extensions. This could take a while...
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0/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 ./siteconf20210427-34377-f5ojwx.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.
解决办法:执行 sudo gem install -n /usr/local/bin cocoapods -v 1.8.4
其实就是指定版本。1.10以上的版本据说有问题。我在这里被卡很久了,找了一个下午的才解决。附上参考链接:https://developer.apple.com/forums/thread/668456
最后附上别人的一个较为完整的安装链接。很多小伙伴在文章下面评论了自己遇到的问题以及解决方案,可以翻阅一下评论区,看是否可以解决大家的问题,也已将上面两个问题及解决方案发在了评论区,请移步~
https://www.jianshu.com/p/f43b5964f582
Mac下都自带ruby,但是如果gem版本太老,可能也会有问题。可以升级gem版本,但是因为ruby 的软件源( https://rubygems.org )使用的是亚马逊的云服务,自带的需要翻墙,所以我用的是淘宝的源https://ruby.taobao.org/。据说用Ruby China 社区专注维护的这个源https://gems.ruby-china.org/也可以。
替换Ruby
1.首先执行以下命令,删除原来的ruby源:
$ gem sources --remove https://rubygems.org/
2.替换成淘宝源。(网上说淘宝源有卡的可能,我用的时候没出现卡的现象,所以没有尝试用China社区的,淘宝卡的同学可以尝试用China 社区的源)
$ gem sources -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
$ gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org/
安装CocoaPods
执行sudo gem install cocoapods命令。(大波坑即将到来)
$ sudo gem install cocoapods
问题一(我出现的问题)
ERROR: While executing gem ... (Gem::DependencyError)
Unable to resolve dependencies: cocoapods requires cocoapods-core (= 1.2.1), cocoapods-downloader (< 2.0, >= 1.1.3), cocoapods-trunk (< 2.0, >= 1.2.0), molinillo (~> 0.5.7), xcodeproj (< 2.0, >= 1.4.4), colored2 (~> 3.1), ruby-macho (~> 1.1)
解决方案(更新gem):sudo gem update --system
问题二
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/fuzzy_match
解决方案 :
执行sudo gem install -n /usr/local/bin cocoapods
语句。然后提示gems installed即可。
问题三
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj
解决方案:
sudo gem install -n /usr/local/bin cocoapods --pre
问题四
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
解决方案:
sudo gem install -n /usr/local/bin cocoapods
问题五
Error installing pods:active support requires Ruby version >= 2.2.2
解决方案:
1.查看ruby版本,终端会输出你的ruby 版本信息
$ ruby -v
2.查看目前的所有ruby版本:
$ rvm list known
如果提示command not found 请先安装rvm
$curl -L get.rvm.io | bash -s stable
如果已安装会列出所有的ruby版本:
# 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[.6]
[ruby-]2.3[.3]
[ruby-]2.4[.0]
ruby-head
下面还有一堆就不放了。。。太长了。。。
安装2.2.2: $ rvm install 2.2.2
安装顺利的话就一直下去了,但是有可能会出现以下报错
Requirements installation failed with status: 1
执行以下命令
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2017.12.13更新
问题: 新项目pod install
时报以下错误
MacBook-Pro:Demo wei$ pod install
-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad interpreter: No such file or directory
MacBook-Pro:Demo wei$ pod --version
-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad interpreter: No such file or directory
查资料之后说要更新ruby, 再重装cocoapods.
先后执行了 sudo gem update --system
和 sudo gem install cocoapods
更新ruby没哈, 重装cocoapods不得了...
MacBook-Pro:Demo wei$ sudo gem install cocoapods
Fetching: concurrent-ruby-1.0.5.gem (100%)
Successfully installed concurrent-ruby-1.0.5
Fetching: i18n-0.9.1.gem (100%)
Successfully installed i18n-0.9.1
Fetching: thread_safe-0.3.6.gem (100%)
Successfully installed thread_safe-0.3.6
Fetching: tzinfo-1.2.4.gem (100%)
Successfully installed tzinfo-1.2.4
Fetching: activesupport-4.2.10.gem (100%)
Successfully installed activesupport-4.2.10
Fetching: nap-1.1.0.gem (100%)
Successfully installed nap-1.1.0
Fetching: fuzzy_match-2.0.4.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
没有/usr/bin的权限? !
再查资料, 说是可以修改权限, 又试了试
MacBook-Pro:Demo wei$ sudo chmod 777 /usr/bin
chmod: Unable to change file mode on /usr/bin: Operation not permitted
晋升到没有操作权限? !
再查, 说是Mac在升级为OS X EI Capitan之后, 增加了一个rootless机制, 该机制被称为最后一道防线, 增加了普通用户在使用过程中的安全性...
大神们提供了几个解决方案, 由于时间紧迫, 我采取的最快的一种:
修改路径, 其实就是/usr/bin的权限被禁了, 那就不在/usr/bin下创建, 换个地儿
MacBook-Pro:Demo wei$ sudo gem install -n /usr/local/bin cocoapods
MacBook-Pro:Demo wei$ pod --version
1.3.1
想了解其他解决方案的同学, 移步👇
参考路径: http://blog.csdn.net/yhf_szb/article/details/51809146