史上最全cocoaPods安装及问题解决
Posted 喵渣渣
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了史上最全cocoaPods安装及问题解决相关的知识,希望对你有一定的参考价值。
前言
近期由于入手一台iMac,要重新配置许多东西,众所周知cocoaPods是ios开发的利器,废话不多说,下面开始安装吧。
a.使用RVM对Ruby进行升级
先查看现在的Ruby版本号
输入命令:ruby -v安装RVM
RVM:Ruby Version Manager, Ruby版本管理器,包括Ruby的版本管理和Gem库管理(gemset)
a.先输入:
curl -L get.rvm.io | bash -s stable
b.然后输入:
source ~/.bashrc*
source ~/.bash_profile*
c.测试是否安装正常:
rvm -v用RVM升级Ruby
a.查看当前ruby版本:
ruby - vb.列出已知的ruby版本:
rvm list knownc.安装所需要的Ruby:
rvm install 2.4.0 –with-openssl-dir=/usr/local安装完成之后,查看是否安装成功
输入: ruby -v
b.安装的详细步骤
由于https://ruby.taobao.org不在维护,RubyGems镜像工作将交由Ruby China 负责。所以目前必须将安装请求重定向到Ruby China 镜像。
查看当前的Ruby镜像,输入以下命令:
gem sources -l
输出结果是:
* CURRENT SOURCES *替换之前的Ruby镜像来访问cocoapods
先输入:
gem sources --remove https://rubygems.org/
移除原来的镜像。然后输入:
gem sources -a https://gems.ruby-china.org/
替换成正确的 镜像。验证当前的Ruby镜像,输入以下命令:
gem sources -l
输出结果是:
* CURRENT SOURCES *表示之前的命令执行成功
完成上面的步骤之后执行安装命令
输入:
sudo gem install cocoapods
查看当前的cocoapods的版本号,验证是否安装成功
输入: pod –version
在终端输入 pod search afnnetworking,验证是否有第三方的搜索结果,如果出现搜索结果则安装成功。
c.使用cocoapods安装第三方的步骤
1.打开终端,cd到项目文件夹,输入: pwd
检查是否准确进入指定目录;
2.初始化pod文件: pod init
;
3.打开podfilr文件,删除不必要的代码,可以只保留 platform: iOS, 8.0
;
4.在终端输入想要添加的第三方库:pod search fmdb
;
5.粘贴pod 第三方库名称’, ‘版本号’,进入podfile文件;
6.在终端输入: pod install
或者pod install --verbose --no-repo-update
后者可以忽略更新。
d.一些常见的问题
- 问题一: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.
出现Requiremaents 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/ruby-2.2.2@global
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多兆。(目前淘宝的不可以了,只能用Ruby-China).
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 performinggit pull
on repomaster
.
[!] /usr/bin/git pull –ff-only
原因:Cocoapods的分支不支持当前最新的Xcode版本
解决方法:删除master分支,重新建立新的分支
sudo rm -fr ~/.cocoapods/repo/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给予执行与读取权限
参考资料:
http://www.jianshu.com/p/6ff1903c3f11
http://www.jianshu.com/p/6ff1903c3f11
http://blog.devtang.com/2014/05/25/use-cocoapod-to-manage-ios-lib-dependency/
以上是关于史上最全cocoaPods安装及问题解决的主要内容,如果未能解决你的问题,请参考以下文章