CocoaPods安装大全

写在前面的话

新换了一家单位,技术方案选择了CocoaPods管理三方库,但是在配置CocoaPods时遇到许多问题,这里总结一下遇到的坑

1.查看当前ruby版本

ruby -v

2.升级Ruby环境,首先需要安装rvm(第一步要下载一些东西等两分钟左右)

curl -L get.rvm.io | bash -s stable 

source ~/.bashrc

source ~/.bash_profile

3.查看rvm版本

rvm -v 

显示如下或是其他版本

rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

4.列出ruby可安装的版本信息

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[.10]
[ruby-]2.3[.7]
[ruby-]2.4[.4]
[ruby-]2.5[.1]  // 重点在这里 重点在这里 重点在这里
[ruby-]2.6[.0-preview2]   // 测试版
ruby-head
.....

5.安装一个ruby版本(这里我选择的是2.5.1版本,当然你也可以选择其他的)

rvm install 2.5.1

注意:安装过程中需要两次按下 Enter 键, 第二次按下后需要输入电脑访问密码(不可见,只管输入就行);
如果你电脑没有安装Xcode和Command Line Tools for Xcode以及Homebrew 会自动下载安装,建议提前安装这三者.

这里很多小伙伴会遇到错误:

5.1.因为没有安装Homebrew造成,所以所以所以要提前安装比较好(笔者未验证)

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

5.2.错误Error downloading Command Line Tools

Error downloading Command Line Tools (macOS Mojave version 10.14) for Xcode: 未能验证该更新。
Done.

Error downloading updates.
==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools'
Failed during: /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools

解决办法:

在苹果的开发者下载中心找到 CLT 的 dmg,在 https://developer.apple.com/download/more/ 里面,用免费开发者账户登陆就可以,然后就可以在列表里找到Command Line Tools (macOS 10.14)for Xcode 10.3下载了。

5.3. 错误RPC failed; curl 18 transfer closed with outstanding read data remaining

error: RPC failed; curl 18 transfer closed with outstanding read data remaining

fatal: The remote end hung up unexpectedly

fatal: early EOF

fatal: index-pack failed

原因:curl的postBuffer默认值太小,需要在终端重新配置这个值

解决办法:

5.3.1、将curl的postBuffer值配置为500M,具体值看项目需求,配置成功不会有提示,配置失败会有提示,终端输入命令:
git config —global http.postBuffer 524288000
5.3.2.查看配置,输入命令:
git config —list
5.3.3.终端会列出相关配置
credential.helper=osxkeychain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
user.name=ZBC-CWS
http.postbuffer=524288000
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://github.com/ZBC-CWS/cocoapodsTest.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

查看其中的http.postBuffer对应的值是否是设置的值,如果是,设置成功,否则,设置失败

特别提醒:将curl的postBuffer值配置为500M后,需要重启电脑才生效

6.设置为默认版本

rvm use 2.5.1 --default

7.更换源

sudo gem update --system

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

gem sources --add https://gems.ruby-china.com/

8.为了验证你的Ruby镜像是并且仅是ruby-china,执行以下命令查看

gem sources -l

如果是以下结果说明正确,如果有其他的请自行百度解决

*** CURRENT SOURCES ***

https://gems.ruby-china.com/

9.这时候才正式开始安装CocoaPods

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

10.如果安装了多个Xcode使用下面的命令选择(一般需要选择最近的Xcode版本)

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

11.安装本地库

pod setup

12.执行以上命令后

Setting up CocoaPods master repo
  $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
  Cloning into 'master'...
  remote: Counting objects: 1879515, done.        
  remote: Compressing objects: 100% (321/321), done.        
  Receiving objects:  21% (404525/1879515), 73.70 MiB | 22.00 KiB/

然后就是漫长的等待,当然,网络好的情况下会更快

如果一直安装不成功请参考这里

CocoaPods在pod setup失败解决办法

特别提醒:pod setup时最好是翻墙,否则因为网络原因下载的会巨慢

13.下载安装完成之后可执行下列命令检查是否可用(第一次使用可能要等一会)

pod search AFNetworking

14.CocoaPods的具体使用

新建一个Xcode工程,使用终端cd到工程目录下

创建Podfile文件:

pod init

之后就可以在项目目录里看到一个Podfile文件

打开Podfile文件:

open Podfile

添加:

pod 'AFNetworking'

保存后退出

开始下载:

pod install

CocoaPods版本
pod --version

文章引用

1.CocoaPods安装
2.CocoaPods在pod setup失败
3.cocoapods导入第三方库提示RPC failed curl 18 transfer

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值