1. 程式人生 > >CocoaPods的安裝以及遇到的坑

CocoaPods的安裝以及遇到的坑

以前在新浪微博上總結過一篇關於CocoaPods的文章(主要是自己看的),昨天整電腦,在安裝CocoaPods的過程中,又遇到了一些坑,正好趕上今天比較閒,就總結一下。

一.CocoaPods是什麼?

CocoaPods是一個用Ruby寫的、負責管理iOS專案中第三方開源庫的工具,CocoaPods能讓我們集中的、統一管理第三方開源庫,為我們節省設定和更新第三方開源庫的時間。

二.CocoaPods的安裝

因為Mac電腦自帶Ruby環境,我們就只需開啟終端開始動手。

(1)、將Ruby 的軟體源替換成國內的

ruby 的軟體源( https://rubygems.org )使用的是亞馬遜的雲服務,所以自帶的需要翻牆,但我們可以使用如下程式碼將官方的 ruby 源替換成國內淘寶的源(

https://ruby.taobao.org/ )或者是由 Ruby China 社群專注維護的這個源(https://gems.ruby-china.org/ )。(我在映象的時候開始用的是淘寶的,但會卡死,可能是不能用了,也可能是網速慢,在後面講“坑”的時候會說)。在這我用的是Ruby China 社群專注維護的這個源(https://gems.ruby-china.org/)。

##(注意:複製別人的命令時不要將$也複製,終端是一直自動帶著的)
*首先,執行以下命令刪除原來的ruby源:

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

執行命令後可在終端看見以下資訊:

https://rubygems.org/ removed from sources
gem sources -a https://gems.ruby-china.org/

*驗證新源是否替換成功

gem sources -l

終端輸出:

 *** CURRENT SOURCES ***
 https://gems.ruby-china.org/

到此ruby 源替已經換成國內的源

(2)、開始安裝 CocoaPods

其實就是執行sudo gem install cocoapods命令這麼簡單,但這一步是最容易出現坑的。

=========可能出現的狀況(坑)=========

問題一:While executing gem ... (Errno::EPERM)  Operation not permitted - /usr/bin/fuzzy_match    錯誤

解決方案 :

執行sudo gem install -n /usr/local/bin cocoapods  語句。然後提示gems installed即可。

問題二:Error installing pods:active support requires Ruby version >= 2.2.2

解決方案 :

檢視ruby版本

$ruby -v

終端會輸出你的ruby 版本資訊

檢視目前的所有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[.8]
[ruby-]2.2[.4]
[ruby-]2.3[.0]
[ruby-]2.2-head
ruby-head
......

安裝2.2.2:

$rvm install 2.2.2

終端執行結果:(如果直接成功請繞過homebrew的解除安裝安裝)

Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/10.11/x86_64/ruby-2.2.2.tar.bz2
Checking requirements for osx.
About to install Homebrew, press `Enter` for default installation in `/usr/local`,
type new path if you wish custom Homebrew installation (the path needs to be writable for user)
:

回車:

It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
ruby -e "$(curl -fsSL  
"The current contents of /usr/local are .git
Requirements installation failed with status: 1.

出現Requirements installation failed with status: 1.時才執行:

$ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

解除安裝home-brew

Warning: This script will remove:/Library/Caches/Homebrew//usr/local/.git/
Are you sure you want to uninstall Homebrew? [y/N] y
==> Removing Homebrew installation...
==> Removing empty directories...
==> Homebrew uninstalled!
You may want to restore /usr/local's original permissions
  sudo chmod 0755 /usr/local
  sudo chgrp wheel /usr/local

再執行:

$ rvm install 2.2.2

提示:

Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/10.11/x86_64/ruby-2.2.2.tar.bz2
Checking requirements for osx.
About to install Homebrew, press `Enter` for default installation in `/usr/local`,
type new path if you wish custom Homebrew installation (the path needs to be writable for user):

按回車:

==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
Password:

這裡需要輸入電腦密碼:

==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown haha /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 501, done.
remote: Compressing objects: 100% (445/445), done.
remote: Total 501 (delta 29), reused 360 (delta 27), pack-reused 0
Receiving objects: 100% (501/501), 787.83 KiB | 169.00 KiB/s, done.
Resolving deltas: 100% (29/29), done.
From https://github.com/Homebrew/brew
 * [new branch]      master     -> origin/master
HEAD is now at 32f7e73 download_strategy: ensure fixed commit hash length
==> Tapping homebrew/core
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 3714, done.
remote: Compressing objects: 100% (3598/3598), done.
remote: Total 3714 (delta 14), reused 2112 (delta 6), pack-reused 0
Receiving objects: 100% (3714/3714), 2.88 MiB | 240.00 KiB/s, done.
Resolving deltas: 100% (14/14), done.
Checking connectivity... done.
Checking out files: 100% (3717/3717), done.
Tapped 3591 formulae (3,740 files, 9.0M)
==> Installation successful!
==> Next steps
Run `brew help` to get started
Further documentation: https://git.io/brew-docs
==> Homebrew has enabled anonymous aggregate user behaviour analytics
Read the analytics documentation (and how to opt-out) here:
https://git.io/brew-analytics
Installing requirements for osx.
Updating system.....
Installing required packages: autoconf, automake, libtool, pkg-config, libyaml, readline, libksba, openssl........
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
ruby-2.2.2 - #configure
ruby-2.2.2 - #download
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
100 6854k  100 6854k    0     0  61342      0  0:01:54  0:01:54 --:--:--  132k
ruby-2.2.2 - #validate archive
ruby-2.2.2 - #extract
ruby-2.2.2 - #validate binary
ruby-2.2.2 - #setup
ruby-2.2.2 - #gemset created /Users/haha/.rvm/gems/[email protected]
ruby-2.2.2 - #importing gemset /Users/haha/.rvm/gemsets/global.gems..............................
ruby-2.2.2 - #generating global wrappers........
ruby-2.2.2 - #gemset created /Users/haha/.rvm/gems/ruby-2.2.2
ruby-2.2.2 - #importing gemsetfile /Users/haha/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.2.2 - #generating default wrappers........
Updating certificates in '/etc/openssl/cert.pem'.
mkdir: /etc/openssl: Permission denied
mkdir -p "/etc/openssl" failed, retrying with sudo
haha password required for 'mkdir -p /etc/openssl': 
and sudo mkdir worked

至此ruby2.2.2就安裝好了,也可以直接安裝更高的版本,只需將版本號修改一下

然後我們繼續sudo gem install cocoapods

問題三、Setting up CocoaPods master repo 卡著不動

出現Setting up CocoaPods master repo,說明Cocoapods正在將它的資訊下載到 ~/.cocoapods裡;(這一步是很費時間的,等輸出Setup completed 安裝完成啦)
在此過程中可以右擊終端選 --->新建視窗;在新建的終端視窗輸入:

cd ~/.cocoapods

進入cocoa pods檔案,然後在終端輸入:

du -sh *

即可檢視下載的檔案大小。也就可以知道是網速不好,還是源不可用了。

解決方案 :

1、第一次我用淘寶的https://ruby.taobao.org/ 替換自帶的軟體源,du -sh *檢視下載的檔案大小,一直不變(不知道是網速的原因,還是淘寶這個源不可用)。然後我就換到這個源https://gems.ruby-china.org/ 。重新搞了一遍。它的下載速度還是蠻快的,檔案大約是800多兆。

2、也可以使用cocoapods的映象索引.
所有專案的Podspec檔案都託管在https://github.com/CocoaPods/Specs ,第一次執行pod setup時,CocoaPods會將這些podspec索引檔案更新到本地的~/.cocoapods目錄下,這個索引檔案比較大,所以第一次更新時非常慢.友好人士在國內的伺服器建立了Cocoapods索引庫的映象,所以執行索引跟新操作時候會快很多.具體操作方法如下:
   $ pod repo remove master
   $ git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/master
   $ pod repo update
這是使用gitcafe上的映象,將以上程式碼中的 https://gitcafe.com/akuandev/Specs.git 替換成 https://git.oschina.net/akuandev/Specs.git 即可使用oschina上的映象。

問題四、出現如下

[!] An error occurred while performing `git pull` on repo `master`.
[!] /usr/bin/git pull --ff-only

原因: Cocoapods的分支不支援當前最新的Xcode版本

解決辦法: 刪除master分支 重新建立新的分支

sudo rm -fr ~/.cocoapods/repos/master

然後再: pod setup

第五個問題是在別人的部落格中看到的

問題五:解決升級EI Capiton CocoaPods "pod: command not found"

升級OS X EI Capiton之後,發現CocoaPods的pod無效了,執行pod後顯示:"pod: command not found"的錯誤。

解決步驟:

1.為了安全起見,執行命令"sudo gem uninstall cocoapods",解除安裝原有的CocoaPod
2.執行命令"sudo gem install -n /usr/local/bin cocoapods"來重新安裝cocoapod
3.如果沒有許可權執行pod,執行命令"sudo chmod +rx /usr/local/bin/",賦予/usr/local/bin給予執行與讀取許可權

三、CocoaPods的使用

(1)查詢第三方庫

 pod search AFNetworking

(2)、建立Podfile檔案
在終端使用cd +路徑切換到專案所在檔案下,然後輸入:

touch Podfile

就可以在專案目錄裡看到Podfile檔案。也可以使用

pod init

來建立,
開啟Podfile檔案:

open Podfile

然後 pod install就可以了

pod install與pod update區別:

1.使用pod install來安裝新的庫,即使你的工程裡面已經有了Podfile,並且已經執行過pod install命令了;所以即使你是新增或移除庫,都應該使用pod install。
2.使用pod update [PODNAME] 只有在你需要更新庫到更新的版本時候用。

小技巧:

最近使用CocoaPods來新增第三方類庫,無論是執行pod install還是pod update都卡在了Analyzing dependencies不動原因在於當執行以上兩個命令的時候會升級CocoaPods的spec倉庫,加一個引數可以省略這一步,然後速度就會提升不少。加引數的命令如下:

pod install --verbose --no-repo-updatepod update --verbose --no-repo-update

相關推薦

win7安裝homestead小結

具體步驟如下連結 問題1:vagrant up 後報錯Vagrant could not detect VirtualBox! 解決方法: 1、進入vagrant 安裝目錄查詢base.rb(F:\HashiCorp\Vagrant\embedded\gems\2.

Centos下GitLab安裝,修改預設埠,解決502錯誤

本次實戰參考《GitLab安裝》,連結如下:https://www.cnblogs.com/xiewenming/p/7304863.html安裝步驟:1.部署gitlab需要的postfixyum install curl policycoreutils openssh-s

阿里雲ECS Ubuntu14.04上安裝PHP7

安裝PHP7,遇坑: 已經把源配置成阿里雲自己的源了,沒有PHP7?我??? 百度了一下,看到了這個冰淤大牛的《阿里雲ECS部署:ubuntu+nginx+mysql+laravel+php7+redis+nodeJS》,參見http://www.jianshu.com

CocoaPods安裝以及遇到的

以前在新浪微博上總結過一篇關於CocoaPods的文章(主要是自己看的),昨天整電腦,在安裝CocoaPods的過程中,又遇到了一些坑,正好趕上今天比較閒,就總結一下。 一.CocoaPods是什麼? CocoaPods是一個用Ruby寫的、負責管理iOS專案中第三方開源庫的工具,CocoaPods能讓

AIX--zabbix agnet的編譯安裝以及遇到的“

AIX ZABBIX AGENT 前文再續,書接上一回。 上一篇講的是AIX 6.1操作系統的安裝,可是胡哥的任務還沒完成呀,老板需要的是zabbix agent的編譯安裝。既然需要編譯,那怎麽能少gcc這個編譯利器呢?工欲善其事必先利其器,咱們先來安裝gcc吧。(可從http://www.bul

Centos7下安裝Python3+scrapy以及

1.安裝支援管理工具 [[email protected] ~]# yum -y groupinstall "Development tools" 2.支援庫的安裝 [[email protected]

centos7 u盤安裝遇到的以及靠譜解決方法。

首先在官網下載centos7的iso檔案,大約4個G,然後推薦使用ultra ISO軟體來製作U盤啟動盤,主要是用ISO軟體開啟映象檔案,然後選擇製作硬碟啟動,選擇u盤,直接next就行,大約14min就OK。一個centos7的U盤啟動製作完畢。 接下來就是u盤安裝系統的過程,插入U盤,F12鍵

Scourcetree安裝以及相關問題小結

Y3   Scourcetree是一款強大的Git/Mercurial桌面客戶端,支援mac系統合Windows系統,用來管理git專案很方便。安裝之前,你需要一個程式碼託管平臺,在此推薦註冊並使用github或者碼雲網都可以。 推薦github使用教程 推薦碼雲使用教程 下

CoCoaPods安裝(ruby映象域名改變之後 浪費了半天時間,希望大家不要再掉)

Cocoapods安裝過程 1.升級Ruby環境 gem update –system 如果沒有許可權 sudo gem update –system 2.替換映象 2.1 檢視當前映象 gem sources -l 2.2 刪除當前映象 gem sources –

linux centos7安裝tomcat7以及遇到的解決辦法

前言:最近買了一個阿里雲伺服器準備安裝tomcat做web容器,之前安裝tomcat是so easy的事情,這次安裝卻遇到了很多個坑,再次總結一下,避免以後自己再出現同樣的錯誤。 一、安裝tomcat 1 下載tomcat 2 安裝tomcat 安裝好jd

linux centos7安裝tomcat8以及遇到的解決辦法

下載tomcat 下載路徑:http://tomcat.apache.org/download-80.cgi 在/usr/local 下 新建 tomcat目錄 使用winSCP將apache-tomcat-8.5.37.tar.gz安裝包複製到tomcat目錄下 輸

Linux 下安裝 Elasticsearch5.6.x 詳細步驟以及解決方案

簡介 網上有各種ES版本的安裝步驟和問題解決方案,但是在安裝過程中還是遇到了許多問題,那麼今天來整理一份詳細的安裝過程以及碰到的問題和心得;有什麼不對的和問題希望大家留言一起討論。 jdk至少需要在1.8.0_73以上版本。 linux的核心版本需要在2.6以上(我用的

關於安裝cocoapods遇到的一些(ERROR: Error installing cocoapods: activesupport requires Ruby version >= 2.2)

1.移除現有的Ruby $gem sources --remove https://rubygems.org/ 2.使用淘寶映象 $gem sources -a https://ruby.taobao.org/ 3.驗證當前ruby版本 $gem sources

CocoaPods安裝和使用教程以及一些常見問題

CocoaPods安裝和使用教程 目錄 CocoaPods是什麼?如何下載和安裝CocoaPods?如何使用CocoaPods? 場景1:利用CocoaPods,在專案中匯入AFNetworking類庫場景2:如何正確編譯執行一個包含CocoPods類庫的專案補充Coc

關於sublime-text外掛的安裝以及安裝過程中遇到的相關問題

一:下載安裝版本sublime-text 地址:https://pan.baidu.com/s/1kWXxLEv(內含註冊碼,我用得是3142便攜版的)二:安裝package control1:開啟控制檯 (快捷鍵:ctrl+`) (不用快捷鍵view->show Co

前端小白學習安裝node npm vue webpack所

1.package.json 依賴包不全的時候 npm install 重新裝一下就可以了。 2.npm run dev 一定要在專案目錄下執行 否則會提示找不到package json。 3.mac使用者一定要記得命令前加sudo。

CocoaPods安裝以及一些常見安裝錯誤解決辦法

注:cocoa pods 已經更新了到1.1.1了,下面的方法不太,不會更新的朋友請看我的另一篇部落格:http://blog.csdn.net/wyz670083956/article/details/53517136 以前的專案都沒有用Cocoapods,引入第三方

spark2.3安裝以及遇到的一些

最近公司的基於CDH的Hadoop大資料計算平臺需要遷移,由於時間過長,原來的搭建步驟以及踩過的坑都忘得差不多了,現在為了將來能夠有個依據,特將本次重新搭建平臺所踩的坑給記錄下來。    使用的軟體及版本:        CDH-5.14.2-1.cdh5.14.2.p0.3

CocoaPods安裝,使用以及錯誤資訊

一、安裝 1.升級Ruby環境 sudo gem update –system 2.安裝CocoaPods時我們要訪問cocoapods.org,用淘寶的RubyGems映象來代替官方版本,執行以下命令: gem sources --remove ht

SSIS安裝以及安裝好找不到商業智能各種

重裝系統 css doc srs 分享圖片 .com release tps ews 原文:SSIS安裝以及安裝好找不到商業智能各種坑 這兩天為了安裝SSIS,各種頭疼。記錄一下,