美文网首页
CocoaPods的安装和遇到的问题

CocoaPods的安装和遇到的问题

作者: Engandend | 来源:发表于2018-04-04 17:51 被阅读0次

温馨提示: 如果在安装中 切换网络 依然出现curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused 可参考这篇文章
主要步骤: 前往文件夹 输入 /etc 找到hosts 文件 ,拷贝出来,在里面添加 文章中的几行代码, 保存之后 再替换etc中的hosts

1、安装RVM

1.1 确定是否存在RVM

输入 rvm -v, 查看命令执行是否成功。
如果输出-bash: rvm: command not found 表示RVM不存在,需要安装。

如果输出rvm 1.29.10 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io] 表示RVM存在,可以进行下一步。

1.2 安装RVM

如果RVM不存在,需要重新安装。
输入命令curl -L get.rvm.io | bash -s stable或者curl -L https://get.rvm.io | bash -s stable
会自动开始下载。

macdeiMac:~ mac$ curl -L https://get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0     24      0  0:00:08  0:00:08 --:--:--    44
  0     0    0     0    0     0      0      0 --:--:--  0:00:09 --:--:--     0
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
macdeiMac:~ mac$ curl -L get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0    299      0 --:--:-- --:--:-- --:--:--   299
100 24535  100 24535    0     0   3258      0  0:00:07  0:00:07 --:--:--  5547
Downloading https://github.com/rvm/rvm/archive/1.29.10.tar.gz
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
.....

  * To start using RVM you need to run `source /Users/mac/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.

👉  Donate: https://opencollective.com/rvm/donate

出现提示之后,表示下载完成,按照提示,要执行source ~/.rvm/scripts/rvm来安装。
执行rvm -v 来确定是否安装成功。正确输出,表示安装成功。

2、安装 brew

1.1 确定是否存在brew

输入brew -v,
如果输出-bash: brew: command not found 则没有安装,需要安装。

如果输出brew ..... 表示brew存在,可以进行下一步。

1.2 安装brew
  • 官方 --- - ⚠️ 不建议尝试
    输入 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 。等待自动下载。
    如果出现curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused 表示网络环境有问题,可以切换不同的网络试试

  • 镜像方式 强烈推荐 NB的飞起
    简单五步安装brew

1、升级ruby

其实此步骤一般来说是不需要的,因为本来系统自带的应该都是2.3.3(要求最低是2.2)已经满足安装cocoapod的要求了
,但是作为强迫症的我,既然之后了还有更高的版本,我就想升到最新版本

查看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[.7]

[ruby-]2.3[.4]

[ruby-]2.4[.1]

ruby-head

ruby的最新版本是2.4.1

查看本地ruby的版本

ruby -v

结果:ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin17](这行输入是在升级成功之后补上的)

如果不是最新的版本,接下来可以进行ruby升级

既然要升级,当然升级为最高版本

rvm install 2.4

注意这里我输入的是2.4 (在往上其他帖子上看到有人输入 2.4.1升级失败的,我没有试过)

此时可能会出现这样的错误:

Error running 'requirements_osx_brew_update_system ruby-2.3.3',
showing last 15 lines of /Users/baidu/.rvm/log/1470726560_ruby-2.3.0/update_system.log
https://github.com/Homebrew/homebrew/wiki/Common-Issues
and make sure `brew update` works before continuing.'

是什么意思没搞明白,但是有一个关键点make sure 'brew update' works before continuing.',意思是:在继续之前确保‘brew update’在工作。

这个时候需要进行brew update操作

在终端输入
brew update

如果此时有错误提示

fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Error: Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core failed!

说明此时的源地址不能访问。
这是因为我们大中华的网络和其他地方的不一样
解决办法就是替换源,网上有很多,比如中科大、清华,这篇文章可做参考

我在知乎的问答上找到另一个源:coding.net的

输入命令:
cd "$(brew --repo)" && git remote set-url origin https://git.coding.net/homebrew/homebrew.git

cd $home && brew update

下面就是一个时间比较长的等待,最后的结果是

Updated 1 tap (homebrew/core).

==>New Formulae

ask-cli            jthread            parallelstl        scrcpy

composer            latexdiff          php-code-sniffer    template-glib

flintrock          libdazzle          php-cs-fixer        wp-cli

ghc@8.2            lm4tools            phpunit

goto                meson-internal      qsoas

jsonrpc-glib        mint                rtptools

==>Updated Formulae

icu4c ✔                    gpredict                  nginx

node ✔                    gqview                    nicotine-plus

..........//内容太长的省略

goocanvas                  neomutt                    zstd

gosu                      netcdf

gpa                        newsboat

==>Renamed Formulae

php56 -> php@5.6          php70 -> php@7.0          php71 -> php@7.1

ok,到这里 最开始出现的问题解决了 “brew update”已经工作了,接下来就可以进行升级ruby的操作了

终端输入:rvm install 2.4
在长时间等待之后经过了绿色、棕色、黑色的字颜色交替后 最后得到


Searching for binary rubies, this might take some time.

No binary rubies available for: osx/10.13/x86_64/ruby-2.4.1.

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.........

Installing required packages: autoconf, automake, libtool, pkg-config, coreutils, libyaml, readline, libksba, openssl@1.1.........

Certificates bundle '/usr/local/etc/openssl@1.1/cert.pem' is already up to date.

Requirements installation successful.

Installing Ruby from source to: /Users/jasonOs/.rvm/rubies/ruby-2.4.1, this may take a while depending on your cpu(s)...

ruby-2.4.1 - #downloading ruby-2.4.1, this may take a while depending on your connection...

  % Total    % Received % Xferd  Average Speed  Time    Time    Time  Current

                                 Dload  Upload  Total  Spent    Left  Speed

100 11.9M  100 11.9M    0    0  29999      0  0:06:59  0:06:59 --:--:-- 54073

ruby-2.4.1 - #extracting ruby-2.4.1 to /Users/jasonOs/.rvm/src/ruby-2.4.1....

ruby-2.4.1 - #applying patch /Users/jasonOs/.rvm/patches/ruby/2.4.1/random_c_using_NR_prefix.patch.

ruby-2.4.1 - #configuring......................................................-

ruby-2.4.1 - #post-configuration.

ruby-2.4.1 - #compiling........................................................-

ruby-2.4.1 - #installing.......

ruby-2.4.1 - #making binaries executable..

ruby-2.4.1 - #downloading rubygems-2.6.14

  % Total    % Received % Xferd  Average Speed  Time    Time    Time  Current

                                 Dload  Upload  Total  Spent    Left  Speed

100  751k  100  751k    0    0  24898      0  0:00:30  0:00:30 --:--:-- 20034

No checksum for downloaded archive, recording checksum in user configuration.

ruby-2.4.1 - #extracting rubygems-2.6.14....

ruby-2.4.1 - #removing old rubygems.........

ruby-2.4.1 - #installing rubygems-2.6.14...........................

ruby-2.4.1 - #gemset created /Users/jasonOs/.rvm/gems/ruby-2.4.1@global

ruby-2.4.1 - #importing gemset /Users/jasonOs/.rvm/gemsets/global.gems.........|

ruby-2.4.1 - #generating global wrappers........

ruby-2.4.1 - #gemset created /Users/jasonOs/.rvm/gems/ruby-2.4.1

ruby-2.4.1 - #importing gemsetfile /Users/jasonOs/.rvm/gemsets/default.gems evaluated to empty gem list

ruby-2.4.1 - #generating default wrappers........

ruby-2.4.1 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).

Install of ruby-2.4.1 - #complete 

Ruby was built without documentation, to build it run: rvm docs generate-ri

看到了Install of ruby-2.4.1 - #complete 表示ruby已经升级到了最新版本
升级成功后再次查看ruby 的版本看看是不是2.4.1
ruby -v

2、安装CocoaPods

接下来就开始安装cocoapod了
这个步骤参考了这篇文章(但是这篇文章的最后 pod setup不成功)

步骤1、升级Ruby环境

终端输入:

sudo gem update --system

中间需要输入密码,(输入密码时,光标不会移动,输完之后直接回车就好)

步骤2、更换Ruby镜像

1、先看现在的镜像地址:
输入命令: gem sources -l
如果是

*** CURRENT SOURCES ***
https://rubygems.org/

需要替换成国内的。如果本身就是国内的镜像,则不需要步骤2的操作

2、替换成国内镜像
先移除现在的镜像
终端输入:
gem sources --remove https://rubygems.org/

然后替换成现在大中华地区可用的(taobao的那个镜像已经不好用了)
gem sources -a https://gems.ruby-china.com/

执行完之后查看是否替换成功
gem sources -l
输出结果

*** CURRENT SOURCES ***
https://gems.ruby-china.org/

说明替换成功

3、镜像替换之后开始进行cocoapods安装

终端输入:
sudo gem install -n /usr/local/bin cocoapods

会出现以下输出

Fetching: concurrent-ruby-1.0.5.gem (100%)
Successfully installed concurrent-ruby-1.0.5
Fetching: i18n-0.9.5.gem (100%)
Successfully installed i18n-0.9.5
...................//内容太长的省略
Fetching: cocoapods-1.4.0.gem (100%)
Successfully installed cocoapods-1.4.0
Parsing documentation for concurrent-ruby-1.0.5
Installing ri documentation for concurrent-ruby-1.0.5
Parsing documentation for i18n-0.9.5
Installing ri documentation for i18n-0.9.5
...................//内容太长的省略
Parsing documentation for cocoapods-1.4.0
Installing ri documentation for cocoapods-1.4.0
Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, activesupport, nap, fuzzy_match, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-stats, netrc, cocoapods-trunk, cocoapods-try, molinillo, atomos, CFPropertyList, colored2, nanaimo, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 31 seconds
28 gems installed

之后在执行
pod setup
输出

Setting up CocoaPods master repo
  $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
  Cloning into 'master'...
  remote: Counting objects: 2038413, done.        
  remote: Compressing objects: 100% (6489/6489), done.        
  Receiving objects:  11% (239182/2038413), 47.75 MiB | 2.00 KiB/s

这是一个漫长的等待。。。

你没有看错,我的速度就是2、2、2 ...不过此时我的内心是平静的【大写的滑稽脸】

你可以command+n新建一个终端窗口,执行cd ~/.cocoapods/进入到该文件夹下,然后执行du -sh *来查看大小,每隔几分钟查看一次,他会告诉你,确实是有文件在往里面写【无聊脸】

等待了2个小时之后 见红了 。。。

[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress

Cloning into 'master'...
remote: Counting objects: 2038413, done.        
remote: Compressing objects: 100% (6489/6489), done.        
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

我平静的内心依然毫无波澜。。。

一个文章上找到了解决方案
1、卸载cocoapod(感觉这一步可以省略)
终端输入:
sudo gem uninstall cocoapods
这个时候需要输入电脑密码(请注意,输入密码不是显示,光标也不会动)输入密码之后
此时终端输出:

Remove executables:
    pod, sandbox-pod

in addition to the gem? [Yn]

需要你输入 ‘Y’ 按enter键
终端继续输出:

Removing pod
Removing sandbox-pod
Successfully uninstalled cocoapods-1.4.0

2、重装cocoapods
终端输入:
sudo gem install -n /usr/local/bin cocoapods
终端输出:

Fetching: cocoapods-1.4.0.gem (100%)
Successfully installed cocoapods-1.4.0
Parsing documentation for cocoapods-1.4.0
Installing ri documentation for cocoapods-1.4.0
Done installing documentation for cocoapods after 4 seconds
1 gem installed

终端输入
sudo chmod +rx /usr/local/bin
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
pod setup

此时终端输出:

Setting up CocoaPods master repo
  $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
  Cloning into 'master'...
  remote: Counting objects: 2038845, done.        
  remote: Compressing objects: 100% (6896/6896), done.        
  Receiving objects:  31% (648027/2038845), 111.18 MiB | 126.00 KiB/s  

此时的速度比刚才比,内心已经震精了。。。
上面的进度跑完之后会继续跑下面这行
Resolving deltas: 37% (423306/1144069)
跑完还会跑
Checking out files: 10% (22244/227244)
100%后就看到了期待已久的输出:

CocoaPods 1.5.0.beta.1 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.5.0.beta.1

Setup completed

completed..............................................
此时我的内心汹涌澎湃。。。。。
最后全部安装完整之后 查看了文件大小 1.5G,不敢想象如果用2k的速度,得用多久, 之前也试过,进行pod setup跑了1天 大概到80%几,见红了。。。

相关文章

网友评论

      本文标题:CocoaPods的安装和遇到的问题

      本文链接:https://www.haomeiwen.com/subject/srwkhftx.html