您的位置:首页 > 运维架构

Cocopods安装和升级备忘录

2017-07-22 00:00 141 查看
摘要: Cocopods安装和升级备忘录

这是两个多月前写在mac 备忘录上的一个备忘文档,现在分享出来,希望对新手或者需要的人有帮助

cocopods安装

相关概念解释

Homebrew(brew)

Homebrew(brew) 是macOS上的包管理器,安装命令行工具,详情介绍可以看下面的网址链接

https://github.com/Homebrew/brew

https://brew.sh/

命令行安装brew:

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

Ruby和Gem

Ruby 面向对象的语言

Gem是一个管理Ruby库和程序的标准包,它通过Ruby Gem(如 http://rubygems.org/ )源来查找、安装、升级和卸载软件包,非常的便捷。
Ruby 1.9.2版本默认已安装Ruby Gem

Cocopods

Cocopods是os/osx开发库管理工具,可以使用类似下面的语法配置引入需要用到的第三方库,执行安装命令,Cocopods会自动去下载第三方库并且做好相应的配置,简化了引入第三方库的流程,让开发更简单高效,是iOS开发的必备工具。

platform :ios, '9.0'
inhibit_all_warnings!
source 'https://github.com/CocoaPods/Specs.git'

target 'iosapp' do

pod 'AFOnoResponseSerializer'
pod 'SDWebImage'  , '~>3.8.2'
pod 'YYKit'
pod 'MBProgressHUD'
pod 'TTTAttributedLabel'
pod 'Masonry'
pod 'FMDB'

end

依赖关系

(因为xcode开发工具,他帮我们安装好Unix环境需要的开发包)

Homebrews/Xcode <- RVM <- Ruby <- Cocoapods

安装步骤

I. Homebrew升级

1、brew升级

brew update

可能会报错:Error: /usr/local must be writable!,执行下面的 2~3 步骤解决这个问题

这一步没报错可以跳到 RVM 安装和Ruby安装升级 这个步骤

2、doctor 检查

brew doctor

3、修改权限

sudo chown -R $(whoami) /usr/local

3.1、下载brew

cd "$(brew --repository)" && git fetch && git reset --hard origin/master

4、再次update

brew update

II RVM 安装和Ruby安装升级

RVM (Ruby Version Manager) Ruby的版本管理工具

1、RVM安装

curl -L get.rvm.io | bash -s stable
source ~/.bashrc
source ~/.bash_profile

可能会有红色警告,第2步解决这个问题

In case of problems: https://rvm.io/help and https://twitter.com/rvm_io 
* WARNING: You have '~/.profile' file, you might want to load it,
to do that add the following line to '/Users/aron/.bash_profile':

source ~/.profile

2、rvm list known 查看可用的rub版本

rvm list known

# 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.1、 打开文件 ~/.bash_profile

vim ~/.bash_profile

2.2、 最后添加一行

source ~/.profile

3、安装指定版本,我安装的是2.3.0,版本需要是rvm list known上面出现的版本

rvm install 2.3.0

3.1 文档安装

r
3ff0
vm docs generate-ri  //安装文档,可选

4、查看版本信息

ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin16]

5、ruby源修改

5.0、gem sources -l  //查看源
5.1、gem sources -r https://rubygems.org/  //移除旧的源
5.2、gem sources -a https://gems.ruby-china.org/  //添加新的源

6、Ruby 的其它设置,这部分设置可以省略

http://www.jb51.net/article/70472.htm

切换 Ruby 版本

rvm use 2.2.0

如果想设置为默认版本,这样一来以后新打开的控制台默认的 Ruby 就是这个版本

rvm use 2.2.0 --default

查询已经安装的ruby

rvm list

卸载一个已安装版本

rvm remove 1.8.7

III. cocoapods安装

gem install cocoapods  //安装
pod —version //查看pod的版本

其他操作

*可以再 ~/.bash_profile 文件中添加以下内容提供快捷方式更新pod库

alias podupn="pod _1.1.1_ update --no-repo-update"
alias podup="pod _1.1.1_ update"

*16. 解决Unable to find a pod with name, author, summary, or description matching AFNetworking错误:

rm ~/Library/Caches/CocoaPods/search_index.json

*查看repos文件夹下面所有文件的大小

arondeMac-mini:repos arons$ pwd
/Users/arons/.cocoapods/repos
arondeMac-mini:repos arons$ du -sh *
10M	flspecs
915M	master
arondeMac-mini:repos arons$

升级cocoapods命令

sudo gem install -n /usr/local/bin cocoapods --pre
sudo gem install -n /usr/local/bin cocoapods --pre

删除本地的缓存

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

本地缓存

/Users/aron/Library/Caches/CocoaPods/Pods/Release/

错误QA

具体报错

fatal: The remote end hung up unexpectedly
error: RPC failed; curl 18 transfer closed with outstanding read data remaining


解决方法

git config --global http.postBuffer 524288000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cocopods