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

  如果你的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. Hadoop之yarn调用机制

    1,Mapper方法:如果在map方法之前执行一些程序用setup,之后用cleanup.同理在Reducer方法中也有setup和cleanup. 2,map任务是并行执行,没有谁先谁后,如果是两个 ...

  2. 【poj3260-最少找零】多重背包+完全背包

    多重背包+完全背包. 买家:多重背包:售货员:完全背包: 开两个数组,分别计算出买家,售货员每个面额的最少张数. 最重要的是上界的处理:上界为maxw*maxw+m(maxw最大面额的纸币). (网上 ...

  3. POJ 1062 昂贵的聘礼 (最短路 迪杰斯特拉 )

    题目链接 Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请 ...

  4. AE特效-与MAYA的结合、制作音乐舞蹈太极动作

    http://blog.sina.com.cn/s/blog_a439a2670101fbkk.html AE特效-与MAYA的结合.制作音乐舞蹈太极动作 (2013-07-24 14:44:12) ...

  5. 小苏的Shell编程笔记之六--Shell中的函数

    http://xiaosu.blog.51cto.com/2914416/531247 Shell函数类似于Shell脚本,里面存放了一系列的指令,不过Shell的函数存在于内存,而不是硬盘文件,所以 ...

  6. Linux上Core Dump文件的形成和分析

    原文: http://baidutech.blog.51cto.com/4114344/904419 Core,又称之为Core Dump文件,是Unix/Linux操作系统的一种机制,对于线上服务而 ...

  7. selenium与360极速浏览器driver配置

    1)下载浏览器对应的driver,浏览器版本与driver对应关系,网址:http://www.cnblogs.com/JHblogs/p/7699951.html:driver下载地址:http:/ ...

  8. python反爬之动态字体相关文档

    web_font的一些基本原理 https://blog.csdn.net/fdipzone/article/details/68166388 实例1 猫眼电影 http://www.cnblogs. ...

  9. 【C++】指针和new相关

    看黄邦勇帅的笔记. 指针和new之前觉得已经掌握的很好了,可是看了资料还是get到了新知识.记录一下. 1.指针只支持 4 种算术运算符:++,――,+,-.指针只能与整数加减.指针运算的原则是:每当 ...

  10. pandas求五日线并画图

    import pandas as pd import numpy as np import matplotlib.pyplot as plt stock_data = pd.read_csv('000 ...