美文网首页
Cocoapods安装

Cocoapods安装

作者: 涛歌依旧 | 来源:发表于2020-02-19 19:40 被阅读0次
  • 疫情期间,笔记本开机卡在进度条界面,不想给国家添麻烦,尽量不外出,所以在家格盘重装系统了。安装cocoapods很多次了,每次遇见不同的坑,所以把本次安装的步骤记录下来了,希望能帮助大家,少踩坑。
  • 我这次安装完cocoapods版本是1.8.4,之前安装cocoapods很头疼的一件事就是执行 pod setup 命令,进入漫长的等待,网上有人提供方法把cocoapods仓库离线下载,然后放到目录里,很实用!我文章最后也会把链接附上。但是 ,这次安装完1.8.4这个版本后,我执行 pod setup 命令后,终端没有去下载仓库,我也没有手动导入离线仓库,也安装成功了,大家安装成功后请给我留言,谢谢!

1.升级ruby环境

如果ruby版本太低,安装cocoapods时会有警告:

NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01. 
Gem::Specification#rubyforge_project= called from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/gems/2.3.0/specifications/nokogiri-1.5.6.gemspec:22.
  • 先安装好 RVM,在终端如下命令:
curl -L https://get.rvm.io | bash -s stable

source ~/.bashrc

source ~/.bash_profile

正常终端会输出下面的结果:

Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc
Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc',
but no GPG software exists to validate it, skipping.
Installing RVM to /Users/HaitaoLee/.rvm/
    Adding rvm PATH line to /Users/HaitaoLee/.profile /Users/HaitaoLee/.mkshrc /Users/HaitaoLee/.bashrc /Users/HaitaoLee/.zshrc.
    Adding rvm loading line to /Users/HaitaoLee/.profile /Users/HaitaoLee/.bash_profile /Users/HaitaoLee/.zlogin.
Installation of RVM in /Users/HaitaoLee/.rvm/ is almost complete:

  * To start using RVM you need to run `source /Users/HaitaoLee/.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

但是运气不好的我,又遇见新的坑了,如下,又是网络问题...,我查找原因的时候,很多人安装HomeBrew也遇到这个问题。

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

我是在本地的hosts文件,把151.101.76.133 raw.githubusercontent.com
加进入就解决了,命令我放下面了,加到hosts最后一行就可以。

sudo vi /etc/hosts
  • 查看rvm版本
rvm -v 
rvm 1.29.9 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
  • 列出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[.8]
[ruby-]2.4[.6]
[ruby-]2.5[.5]
[ruby-]2.6[.3]  // 我安装是这个……
[ruby-]2.7[.0-preview1] //预览版
ruby-head

# for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2

# JRuby
jruby-1.6[.8]
jruby-1.7[.27]
jruby-9.1[.17.0]
jruby[-9.2.7.0]
jruby-head

# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx-3[.107]
rbx-4[.3]
rbx-head

# TruffleRuby
truffleruby[-19.1.0]

# Opal
opal

# Minimalistic ruby implementation - ISO 30170:2012
mruby-1.0.0
mruby-1.1.0
mruby-1.2.0
mruby-1.3.0
mruby-1[.4.1]
mruby-2[.0.1]
mruby[-head]

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# Topaz
topaz

# MagLev
maglev-1.0.0
maglev-1.1[RC1]
maglev[-1.2Alpha4]
maglev-head

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# IronRuby
ironruby[-1.1.3]
ironruby-head

  • 安装一个ruby版本(这里我选择的是2.6.3版本,当然你也可以选择其他的)
rvm install 2.6.3
  • 设置为默认版本
rvm use 2.6.3 --default

2.更换Ruby镜像

sudo gem update --system

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

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

验证是否添加成功

gem sources -l
*** CURRENT SOURCES ***

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

3.安装Cocoapods

sudo gem install -n /usr/local/bin cocoapods
Fetching thread_safe-0.3.6.gem
Fetching tzinfo-1.2.6.gem
Fetching concurrent-ruby-1.1.6.gem
Fetching nap-1.1.0.gem
Fetching i18n-0.9.5.gem
Fetching activesupport-4.2.11.1.gem
Fetching fuzzy_match-2.0.4.gem
Fetching httpclient-2.8.3.gem
Fetching algoliasearch-1.27.1.gem
Fetching cocoapods-core-1.8.4.gem
Fetching claide-1.0.3.gem
Fetching cocoapods-deintegrate-1.0.4.gem
Fetching cocoapods-downloader-1.3.0.gem
...
Successfully installed cocoapods-deintegrate-1.0.4
Successfully installed cocoapods-downloader-1.3.0
Successfully installed cocoapods-plugins-1.0.0
Successfully installed cocoapods-search-1.0.0
...
Parsing documentation for cocoapods-1.8.4
Installing ri documentation for cocoapods-1.8.4
Done installing documentation for thread_safe, tzinfo, concurrent-ruby, i18n, activesupport, nap, fuzzy_match, httpclient, algoliasearch, 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 16 seconds

最后一步安装本地库,pod setup
但是我这次执行完命令后,
终端不作为。我在项目执行pod installpod search都成功了。如果大家执行pod setup后,下载仓库进入漫长。。。。的等待,请参考下面的文章:
首次 pod setup 慢的取巧方法

文章最后希望早点战胜疫情,向白衣天使致敬!!!

相关文章

网友评论

      本文标题:Cocoapods安装

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