网上有很多教程,但要么内容很老,要么不详细,要么各种坑的情况没写。最近买新电脑了,正好要走一遍这些流程,所以写下次教程。

  如果你的Ruby版本是2.2.2以上,则忽略下面第一步。查看Ruby版本命令:ruby -v

一、安装RVM及更新Ruby

  安装RVM的目的是为了更新Ruby。

  安装RVM命令:curl -L get.rvm.io | bash -s stable

  可能会出现下面错误:

# 张林峰,
#
# Thank you for using RVM!
# We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team. In case of problems: https://rvm.io/help and https://twitter.com/rvm_io Upgrade Notes: * WARNING: You have '~/.profile' file, you might want to load it,
to do that add the following line to '/Users/zhanglinfeng/.bash_profile': source ~/.profile * No new notes to display.

  意思就是让你打开根目录下的~/.profile这个文件,在文件末尾加上这句话source ~/.profile,保存,重新执行安装RVM命令。

  安装RVM成功后,执行rvm list known命令列出已知的ruby版本。

  我这里最新的是2.4,所以执行安装Ruby命令:rvm install 2.4

  可能会出现报错1:

zhanglinfengdeMacBook-Pro:~ zhanglinfeng$ rvm install 2.4
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.12/x86_64/ruby-2.4..
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
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)
:

  这种情况找不到2.4这个版本,可能你会问刚才列出的ruby版本中有2.4啊。rvm list known命令列出列出的是各个平台中的ruby版本,你这个平台不一定有2.4。看上面错误提示,你点击Enter后会给你安装Homebrew,安装完后会自动给你下载安装ruby2.4。这个过程花的时间比较长。(我猜测如果不点Enter,直接关掉终端,重新打开终端,执行安装一个版本低一点的ruby说不定就不会报这个错)

  查看现在的ruby版本 ruby -v,如果不是2.4,则执行rvm use ruby-2.4,重新查看,发现ruby的版本一变为2.4

  可能会出现报错2:

zhanglingdembp2:~ zhanglinfeng$ rvm install 2.6.
Warning! PATH is not properly set up, '/Users/zhanglinfeng/.rvm/gems/ruby-2.4.0/bin' is not at first place.
Usually this is caused by shell initialization files. Search for 'PATH=...' entries.
You can also re-add RVM to your profile by running: 'rvm get stable --auto-dotfiles'.
To fix it temporarily in this shell session run: 'rvm use ruby-2.4.0'.
To ignore this error add rvm_silence_path_mismatch_check_flag= to your ~/.rvmrc file.
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.14/x86_64/ruby-2.6..
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Installing requirements for osx.
Updating system............
Error running 'requirements_osx_brew_update_system ruby-2.6.3',
showing last lines of /Users/zhanglinfeng/.rvm/log/1585985497_ruby-2.6./update_system.log
++ printf %b '
Xcode version older than 4.6. installed, download and install newer version from: http://connect.apple.com After installation open Xcode, go to Downloads and install Command Line Tools.
\n' Xcode version older than 4.6. installed, download and install newer version from: http://connect.apple.com After installation open Xcode, go to Downloads and install Command Line Tools. ++ return
Requirements installation failed with status: .

这种情况先升级rvm就可以了,升级rvm命令

rvm get master

然后再升级ruby

rvm install 2.4

二、安装CocoaPods

1.安装

  安装CocoaPods命令:sudo gem install cocoapods,但是这个被防火墙了。我们换国内镜像来安装。执行下面两个命令

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

  查看是否换成了国内镜像命令:gem sources -l

  安装CocoaPods命令:sudo gem install cocoapods

  查看本地安装的CocoaPods列表: gem list

  卸载某个版本:

sudo gem uninstall cocoapods -v 0.35.
sudo gem uninstall cocoapods-core -v 0.35.
sudo gem uninstall cocoapods // 卸载所有

  可能出现的问题1:

  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版本问题, 执行下面这句

sudo gem update --system

  可能出现的问题2:

GemWrappers: Can not wrap missing file: pod
GemWrappers: Can not wrap missing file: sandbox-pod

表示你的 gem出问题了执行下面的命令

gem uninstall rubygems-update

2.初始化

pod 需要从指定的源中获取到第三方库, 所以需要对一个'pod源' 进行初始化, 把所有的库映射到本地

pod setup

如果成功,恭喜你后面不用看了。

如果报如下错误

[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `cocoapods`.
You can try adding it manually in `/Users/zhanglinfeng/.cocoapods/repos` or via `pod repo add`.

添加默认的pod源

pod repo add master https://github.com/CocoaPods/Specs.git

查看pod镜像源列表

pod repo list

如果Cloning spec repo `master` from `https://github.com/CocoaPods/Specs.git`一直卡主不动,或者卡了很长时间后出现下面错误

zhanglinfeng@mac LFKit % pod repo add master https://github.com/CocoaPods/Specs.git
Cloning spec repo `master` from `https://github.com/CocoaPods/Specs.git`
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git -- master Cloning into 'master'...
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

我在网上找了很多方法,我也都尝试过,可能对有些人有用,对有些人没用。我是通过方法四解决的。

方法一:把pod源更换成国内镜像源

// 移除现有的镜像
pod repo remove master
// 添加新镜像源
pod repo add master https://gitcafe.com/akuandev/Specs.git
pod repo update
pod setup

已知的国内源有

https://gitcafe.com/akuandev/Specs.git
http://git.oschina.net/akuandev/Specs.git
https://git.coding.net/hging/Specs.git
https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git

但是我试了后前2个国内源分别报如下错误

zhanglinfeng@mac LFKit % pod repo add master https://gitcafe.com/akuandev/Specs.git
Cloning spec repo `master` from `https://gitcafe.com/akuandev/Specs.git`
[!] /usr/bin/git clone https://gitcafe.com/akuandev/Specs.git -- master Cloning into 'master'...
fatal: unable to access 'https://gitcafe.com/akuandev/Specs.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to gitcafe.com:443
zhanglinfeng@mac LFKit % pod repo add master http://git.oschina.net/akuandev/Specs.git
Cloning spec repo `master` from `http://git.oschina.net/akuandev/Specs.git`
[!] /usr/bin/git clone http://git.oschina.net/akuandev/Specs.git -- master Cloning into 'master'...
fatal: unable to access 'http://git.oschina.net/akuandev/Specs.git/': The requested URL returned error: 403

第三个源https://git.coding.net/hging/Specs.git 是add成功了,但是pod install会会出现Cloning spec repo `cocoapods` from `https://github.com/CocoaPods/Specs.git`一直卡主不动,估计是公司项目里指定了这个源的原因,于是我放弃了换国内源的方法,但你们可以试试这个方法,说不定对你们来说可行。

方法二:增加git缓存大小

git config --global http.postBuffer 

结果还是不行,又尝试增大到1G也不行,然后没尝试增到更大,继续找其他方法,你们可以试试更大,说不定可行。

方法三:在github 个人账号的setting中进行SSH keys的配置

可以用sourcetree客户端生成比较简单,偏好设置->账户,如果sourcetree客户端上已经添加了GitHub账户就点编辑,没有就添加一个GitHub账户,协议选择ssh,再点创建秘钥。

也可以命令创建ssh key

ssh-keygen -t rsa -C "邮箱"

如果你有多个代码托管平台,注册的邮箱不一样,想区分不同平台的ssh key,可以生成ssh key并同时保存制定的文件名

ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "邮箱"

其中,id_rsa.github为指定的文件名

配置ssh config文件,如果文件不存在就创建

vim ~/.ssh/config

点击i进入编辑模式,添加

Host github.com
Hostname ssh.github.com
Port
User 用户名
IdentityFile ~/.ssh/id_rsa.github

点击esc退出编辑模式,并输入:wq保存并退出

将 SSH 密钥复制到剪贴板。
如果您的 SSH 密钥文件与示例代码不同,请修改文件名以匹配您当前的设置。 在复制密钥时,请勿添加任何新行或空格。

pbcopy < ~/.ssh/id_rsa.pub

如果 pbcopy 不可用,可找到隐藏的 .ssh 文件夹,在常用的文本编辑器中打开该文件,并将其复制到剪贴板。

不管是sourcetree还是命令创建的key,都要打开GitHub网站,在设置中设置ssh key

测试ssh key是否配置成功

ssh -T git@github.com

可能会看到类似如下的警告:

The authenticity of host 'github.com (IP ADDRESS)' can't be established.
RSA key fingerprint is ::ac:a5:::2d:::1b::4d:eb:df:a6:.
Are you sure you want to continue connecting (yes/no)?

或者

The authenticity of host 'github.com (IP ADDRESS)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?

输入yes,出现

Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

SSH配置成功

然后可以

git clone git@github.com:CocoaPods/Specs.git ~/.cocoapods/repos/master

 方法四:

pod setup
cd ~/.cocoapods/repos
git clone --depth https://github.com/CocoaPods/Specs.git master
cd master
git fetch --unshallow
pod setup
 

方法五:配置GitHub dns

在网站 https://www.ipaddress.com/ 分别搜索对应网址的ip结果

151.101.185.194 github.global-ssl.fastly.net
192.30.253.112 github.com

刷新dns

// 老系统
type dscacheutil -flushcache
// 新系统
sudo killall -HUP mDNSResponder

方法六:使用代理

查看代理端口:
偏好设置-》网络-》连接的网络-》高级-》代理-》SOCKS代理服务器

配置:

打开代理软件,配置好代理之后,去终端输入 git配置命令,命令如下:
git config --global http.https://github.com.proxy socks5://127.0.0.1:10000
如此就从根本上解决了问题,下面附上设置代理前后 git命令的速度
代理前 10k/s ☹️
代理后 600k/s

最新Mac安装CocoaPods详细教程及各种坑解决办法的更多相关文章

  1. 安装WordPress详细教程指南

    最近准备自己建一个个人博客,以便分享一些自己工作生活中的一些观点及经验,建博客当然选wordpress,毕竟wordpress是为博客而生的嘛.下边记录一下自己安装WordPress的详细过程指南,亦 ...

  2. npm安装vue详细教程(图片详解)

    npm安装vue详细教程(图片详解) 一.总结 一句话总结:整个安装流程照着教程来,注意系统环境变量的配置,注意一下npm的本地仓库和缓存位置 教程 系统环境变量 仓库 缓存 1.什么情况下最适合用n ...

  3. iOS安装CocoaPods详细过程

    iOS安装CocoaPods详细过程 一.简介 什么是CocoaPods CocoaPods是OS X和iOS下的一个第三类库管理工具,通过CocoaPods工具我们可以为项目添加被称为“Pods”的 ...

  4. Windows安装Jenkins详细教程(图文教程)

    一.安装前准备 1.提前安装好jdk,可参考以下链接进行安装 Windows安装JDK详细教程(图文教程) 2.Jenkins官网下载安装包(因为本人jdk安装的是1.8,所以会和最新版jenkins ...

  5. Ubuntu下安装JDK详细教程

    Ubuntu下安装JDK详细教程 作者:凯鲁嘎吉 - 博客园http://www.cnblogs.com/kailugaji/ Ubuntu版本:Ubuntu-12.04.5-desktop-i386 ...

  6. Windows下安装MySQL详细教程

    Windows下安装MySQL详细教程 1.安装包下载  2.安装教程 (1)配置环境变量 (2)生成data文件 (3)安装MySQL (4)启动服务 (5)登录MySQL (6)查询用户密码 (7 ...

  7. ubuntu安装scala详细教程

    ubuntu14 安装scala详细教程 1.下载scala压缩包 http://www.scala-lang.org/download/ 2.建立目录,解压文件到所建立目录 $ sudo mkdir ...

  8. Centos7安装Typecho详细教程

    Centos7安装Typecho详细教程   首先搭建LAMPH环境 L linux 服务器(centos或者ubunt) .A Apache .M mysql .P PHP 安装Apache.PHP ...

  9. Linux系统下Dubbo安装的详细教程

    Linux系统下Dubbo安装的详细教程 1.Dubbo的简介 Dubbo是 [1]  阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 [ ...

随机推荐

  1. Planning your upgrade with Upgrade Advisor

    Planning your upgrade with Upgrade Advisor You should use the Upgrade Advisor tool (if it is availab ...

  2. 数据结构之DFS与BFS

    深度搜索(DFS) and  广度搜索(BFS) 代码如下: #include "stdafx.h" #include<iostream> #include<st ...

  3. ByteUtil 工具类

    ByteUtil 工具类 import java.io.FileOutputStream; import java.io.OutputStream; import java.nio.charset.C ...

  4. bzoj4900 [CTSC2017]密钥

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4900 [题解] 恭喜bzoj达到40页 考场由于傻逼基数排序写挂了而gg. 竟然忘了考试前一 ...

  5. python函数篇:名称空间、作用域和函数的嵌套

    一.名称空间:(有3类) (1)内置名称空间(全局作用域) (2)全局名称空间(全局作用域) (3)局部名称空间(局部作用域) 关于名称空间的查询: x=1 def func(): print('fr ...

  6. (转载)常用的Python库

    http://forum.ubuntu.com.cn/viewtopic.php?f=63&t=249573&p=2640959 Tkinter ---- Python默认的图形界面接 ...

  7. POJ1080(LCS变形)

    Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  8. 本地搭建SVN局域网服务器【转】

    转自:http://blog.csdn.net/sunbaigui/article/details/8466310 参考链接:http://tortoisesvn.net/docs/nightly/T ...

  9. 深入理解Java的注解(Annotation):自定义注解入门(2)

    要深入学习注解,我们就必须能定义自己的注解,并使用注解,在定义自己的注解之前,我们就必须要了解Java为我们提供的元注解和相关定义注解的语法. 元注解: 元注解的作用就是负责注解其他注解.Java5. ...

  10. Python 进阶 之 traceback模块

    Traceback模块官方英文描述: Help on module traceback: NAME traceback - Extract, format and print information ...