CocoaPods的安装和遇到的问题

温馨提示: 如果在安装中 切换网络 依然出现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
.....
  * 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 来确定是否安装成功。正确输出,表示安装成功。

1.3 升级RVM

当有新版本的RVM时,想升级了,输入和安装一样的命令:curl -L get.rvm.io | bash -s stable或者curl -L https://get.rvm.io | bash -s stable

Upgrade of RVM in /Users/jasonOs/.rvm/ is complete.

Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.

查看版本rvm -v时,有提示

Please open a new shell or run one of the following commands:

    rvm reload
    echo rvm_auto_reload_flag=1 >> ~/.rvmrc # OR for auto reload with msg
    echo rvm_auto_reload_flag=2 >> ~/.rvmrc # OR for silent auto reload

按照提示需要输入某一个命令 ,此时控制台输入rvm reload

1.4 gem 升级

sudo gem update --system

如果报“无权限”,使用
sudo gem update -n /usr/local/bin --system

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

3、升级ruby

参考来源
其实此步骤一般来说是不需要的,因为本来系统自带的应该都是2.3.3(要求最低是2.2)已经满足安装cocoapod的要求了。

查看当前版本ruby - v

如果想升级版本,采用一下方法:

输入命令: brew install ruby

==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/ca-certificates-2022-10-11.all.bottle
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/openssl%401.1-1.1.1q.monterey.bottle.
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/readline-8.2.1.monterey.bottle.tar.gz
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/ruby-3.1.2_1.monterey.bottle.tar.gz
######################################################################## 100.0%
==> Installing dependencies for ruby: ca-certificates, openssl@1.1 and readline
==> Installing ruby dependency: ca-certificates
==> Pouring ca-certificates-2022-10-11.all.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
🍺  /usr/local/Cellar/ca-certificates/2022-10-11: 3 files, 225.4KB
==> Installing ruby dependency: openssl@1.1
==> Pouring openssl@1.1-1.1.1q.monterey.bottle.tar.gz
🍺  /usr/local/Cellar/openssl@1.1/1.1.1q: 8,097 files, 18.5MB
==> Installing ruby dependency: readline
==> Pouring readline-8.2.1.monterey.bottle.tar.gz
🍺  /usr/local/Cellar/readline/8.2.1: 50 files, 1.7MB
==> Installing ruby
==> Pouring ruby-3.1.2_1.monterey.bottle.tar.gz
==> Caveats
By default, binaries installed by gem will be placed into:
  /usr/local/lib/ruby/gems/3.1.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH, run:
  echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc

For compilers to find ruby you may need to set:
  export LDFLAGS="-L/usr/local/opt/ruby/lib"
  export CPPFLAGS="-I/usr/local/opt/ruby/include"

==> Summary
🍺  /usr/local/Cellar/ruby/3.1.2_1: 15,996 files, 41MB
==> Running `brew cleanup ruby`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> ruby
By default, binaries installed by gem will be placed into:
  /usr/local/lib/ruby/gems/3.1.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH, run:
  echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc

For compilers to find ruby you may need to set:
  export LDFLAGS="-L/usr/local/opt/ruby/lib"
  export CPPFLAGS="-I/usr/local/opt/ruby/include"

安装升级后,再次查看版本,发现还是原来的版本,输入以下命令

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

2、安装CocoaPods

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

步骤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 或者sudo gem install cocoapods -n /usr/local/bin

如果出现权限问题
可更换命令:sudo gem install cocoapods --user-install

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0 directory.

开始下载之后 会出现以下输出

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%几,见红了。。。

Cloning spec repo cocoapods 卡住

cocoaPod安装完之后, 第一次进行pod install操作。可能会出现卡住不动或者的情况,只是由于cocoapPod安装好了, 但是必要的资源还没准备好,后台在默默的下载,具体大小,可根据git的api中的size查看

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

解决办法:
1、去git仓库下载好资源,倒入本地文件夹下.cocoapods/repos/cocoapods/
解决方法来源

image.png

安装cocoapod之后,提示 gem executables will not run

https://www.jianshu.com/p/6f4f253bc254

2、换源
步骤1、更换国内的镜像, 清华的不错
解决方法来源

$ cd ~/.cocoapods/repos 
$ pod repo remove master
$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master

步骤2、项目中的podfile文件修改源地址:

source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

更新时遇到警告

WARNING:  You don't have /Users/xxx/.local/share/gem/ruby/2.6.0/bin in your PATH,
      gem executables will not run.

解决方案:来源于stackoverflow

# 1、打开配置文件
open ~/.zshrc

# 2、在最后加以下2行:
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
export PATH="$PATH:$GEM_HOME/bin"

# 3、重置资源
source ~/.zshrc

放弃了系统的ruby,用第三方代替

由于各种权限问题, 放弃了系统的ruby。安装了rbenv 参考这里安装

curl: (92) HTTP/2 stream 1 was not closed cleanly before end of the underlying stream

[!] Error installing MintegralAdSDK
[!] /usr/bin/curl -f -L -o /var/folders/2m/w24z1m4d1qd2dz_yy15lv6280000gn/T/d20231101-83686-mur3p2/file.zip https://github.com/Mintegral-official/MintegralAdSDK-iOS-new/releases/download/7.4.2/Mintegral_M_SDK.zip --create-dirs --netrc-optional --retry 2 -A 'CocoaPods/1.14.2 cocoapods-downloader/2.0'

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:02:00 --:--:--     0
curl: (92) HTTP/2 stream 1 was not closed cleanly before end of the underlying stream

解决来源

git config --global http.version HTTP/1.1

使用 git 的时候发现一直提示 HTTP/2 stream 1 was not closed cleanly before end of the underlying stream。 通过排查发现,是 git 默认使用的通信协议出现了问题,可以通过将默认通信协议修改为 http/1.1 来解决该问题。

The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods inst

一个cocos2d的工程构件出来的Xcode工程,然后在创建了podfile进行pod 运行后就报错

修改:
修改配置

The singleCarGame-mobile [Debug] target overrides the HEADER_SEARCH_PATHS build setting defined in `Pods/Target Support Files/Pods-singleCarGame-mobile/Pods-singleCarGame-mobile.debug.xcconfig'. This can lead to problems with the CocoaPods installation

The `singleCarGame-mobile [Debug]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-singleCarGame-mobile/Pods-singleCarGame-mobile.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.
image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,491评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,856评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,745评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,196评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,073评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,112评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,531评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,215评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,485评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,578评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,356评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,215评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,583评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,898评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,174评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,497评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,697评论 2 335

推荐阅读更多精彩内容