安裝CocoaPods遇到的坑 2021-4-26更新??

2021-4-26 記安裝CocoaPods最大的一次翻車事故

新電腦。。。 系統(tǒng):macOS Catalina 10.15.5

1. 安裝 Homebrew 的各種花式報錯
  • ping 不通 github.com
    解決方案:進入 hosts 文件中添加 ip
Mac ~ % sudo nano /private/etc/hosts

# 下面是需要添加的內(nèi)容。需要通過 https://www.ipaddress.com/ 查詢域名對應的 ip,科學上網(wǎng)哈
199.232.69.194 github.global.ssl.fastly.net
140.82.112.4 github.com
  • 執(zhí)行 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 報錯
    報錯內(nèi)容大概如下:
    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
# 這里會打開編輯頁,進入編輯模式,粘貼內(nèi)容,保存退出 
$ /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.

解決辦法:執(zhí)行 sudo gem install -n /usr/local/bin cocoapods -v 1.8.4

其實就是指定版本。1.10以上的版本據(jù)說有問題。我在這里被卡很久了,找了一個下午的才解決。附上參考鏈接:https://developer.apple.com/forums/thread/668456

最后附上別人的一個較為完整的安裝鏈接。很多小伙伴在文章下面評論了自己遇到的問題以及解決方案,可以翻閱一下評論區(qū),看是否可以解決大家的問題,也已將上面兩個問題及解決方案發(fā)在了評論區(qū),請移步~
http://www.itdecent.cn/p/f43b5964f582


Mac下都自帶ruby,但是如果gem版本太老,可能也會有問題??梢陨塯em版本,但是因為ruby 的軟件源( https://rubygems.org )使用的是亞馬遜的云服務,自帶的需要翻墻,所以我用的是淘寶的源https://ruby.taobao.org/。據(jù)說用Ruby China 社區(qū)專注維護的這個源https://gems.ruby-china.org/也可以。

替換Ruby

1.首先執(zhí)行以下命令,刪除原來的ruby源:
$ gem sources --remove https://rubygems.org/
2.替換成淘寶源。(網(wǎng)上說淘寶源有卡的可能,我用的時候沒出現(xiàn)卡的現(xiàn)象,所以沒有嘗試用China社區(qū)的,淘寶卡的同學可以嘗試用China 社區(qū)的源)

$ gem sources -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
$ gem sources -l
*** CURRENT SOURCES ***

https://ruby.taobao.org/

安裝CocoaPods

執(zhí)行sudo gem install cocoapods命令。(大波坑即將到來)
$ sudo gem install cocoapods

問題一(我出現(xiàn)的問題)
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

解決方案 :
執(zhí)行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
安裝順利的話就一直下去了,但是有可能會出現(xiàn)以下報錯
Requirements installation failed with status: 1
執(zhí)行以下命令
$ 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.
先后執(zhí)行了 sudo gem update --systemsudo 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的權(quán)限? !
再查資料, 說是可以修改權(quán)限, 又試了試

MacBook-Pro:Demo wei$ sudo chmod 777 /usr/bin
chmod: Unable to change file mode on /usr/bin: Operation not permitted

晉升到?jīng)]有操作權(quán)限? !
再查, 說是Mac在升級為OS X EI Capitan之后, 增加了一個rootless機制, 該機制被稱為最后一道防線, 增加了普通用戶在使用過程中的安全性...
大神們提供了幾個解決方案, 由于時間緊迫, 我采取的最快的一種:
修改路徑, 其實就是/usr/bin的權(quán)限被禁了, 那就不在/usr/bin下創(chuàng)建, 換個地兒

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容