新的iMac安裝pod遇到了很多的問題,一直失敗,網(wǎng)上查找的各種方法貌似都過時(shí)了粗俱。經(jīng)過努力,最終安裝成功虚吟。
安裝要點(diǎn)
- 檢查ruby的源
gem sources -l
注意:-l為list中的l寸认,不是數(shù)字1
顯示如下:
*** CURRENT SOURCES ***
https://rubygems.org/
或者為
https://ruby.taobao.org/
上面兩個(gè)源目前都不能使用了。我的最開始安裝失敗的原因就是使用了淘寶的源串慰。
- 移除舊源偏塞,添加新源
移除舊源
$ gem sources --remove https://ruby.taobao.org/
https://ruby.taobao.org/ removed from sources
添加新源
$ gem sources -a http://gems.ruby-china.org/
http://gems.ruby-china.org/ added to sources
如果http://gems.ruby-china.org/也不可用,可以改為添加https://gems.ruby-china.com
檢查下
$ gem sources -l
*** CURRENT SOURCES ***
http://gems.ruby-china.org/
顯示已經(jīng)添加成功
- 更新下gem版本
$ sudo gem update --system
如果是最新的版本會(huì)顯示
Latest version currently installed. Aborting.
- 安裝cocoapods
安裝最新版本
sudo gem install -n /usr/local/bin cocoapods --pre
安裝制定版本
sudo gem install -n /usr/local/bin cocoapods -v 1.10.2
安裝成功會(huì)顯示:
Installing ri documentation for cocoapods-1.3.1
22 gems installed
- 驗(yàn)證
輸入下面命令查看pod版本
$ pod --version
1.3.1
證明安裝成功
升級(jí) cocoapods
如果是以前安裝過邦鲫,要升級(jí)灸叼,直接執(zhí)行以下命令即可
sudo gem install cocoapods -n /usr/local/bin
卸載 cocoapods
sudo gem uninstall cocoapods
此時(shí),會(huì)出現(xiàn)如圖所示的提示
提示
-
選擇想要卸載的版本,我選的 2怜姿,然后回車
會(huì)出現(xiàn)如圖所示的提示慎冤,顯示卸載成功
卸載結(jié)果 - 檢查下 pod 版本
pod --version
當(dāng)前版本
顯示卸載成功
遇到的問題
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版本過低疼燥,需要update沧卢,執(zhí)行下述命令:
$ gem update --system
ERROR: While executing gem ... (OpenSSL::SSL::SSLError)
hostname "gems.ruby-china.org" does not match the server certificate
原因:使用的源證書無效,需要更換新的源醉者,參照步驟1但狭、2解決此問題。
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
原因:沒有操作權(quán)限撬即,在更新命令前加上sudo即可立磁。例如更新gem
$ sudo gem update --system
如果仍然提示同樣的錯(cuò)誤,則使用下面的命令:
sudo gem install cocoapods --user-install
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj
原因:沒有權(quán)限不能操作剥槐,解決方法是
sudo gem install -n /usr/local/bin cocoapods --pre
Error fetching http://gems.ruby-china.org/:
bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz)
原因:ruby-china 更換了域名唱歧,變?yōu)?https://gems.ruby-china.com,需要使用 gem sources -a https://gems.ruby-china.com/
1518155-c942476077037717.png
如果有下面的警告粒竖,需要將更新下環(huán)境變量
WARNING: You don't have /Users/xxx/.local/share/gem/ruby/2.6.0/bin in your PATH, gem executables will not run.
export PATH="/Users/xxx/.local/share/gem/ruby/2.6.0/bin":$PATH
否則安裝成功后會(huì)提示找不到 pod 命令