Mac M2 Pro安装使用Cocoapods

Mac Pro M2安装使用Cocoapods

在新公司要做iOS开发,所以在新电脑上安装Cocoapods

在升级gem,sudo gem update --system,和安装cocoapods时都遇到如下的提示:

bash 复制代码
ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/gem

原因大概是:Apple已内置安装了ruby,不能修改

参考:

the reason why you are getting that error is because Apple doesn't allow you to install gems directly into the version of Ruby that came preinstalled on your Mac

其中的一个解决办法就是,可通过安装ruby版本管理器来解决,如chruby或者RVM

安装chruby

参考Install Ruby 3.1 · macOS

bash 复制代码
brew install ruby-install chruby

安装后按提示,在.zshrc 中写入如下的内容:

bash 复制代码
source /opt/homebrew/opt/chruby/share/chruby/chruby.sh
source /opt/homebrew/opt/chruby/share/chruby/auto.sh
chruby ruby-3.1.2

然后安装Ruby,如下的代码安装并使用最新的ruby

bash 复制代码
ruby-install --latest ruby

安装之前看下当前系统的ruby的版本:

bash 复制代码
ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]

SwitchHosts

在安装过程中,可能会提示raw.githubusercontent.com网站的内容不能访问,此时需要配置host,推荐安装SwitchHosts

host配置如下:

bash 复制代码
185.199.110.133  raw.githubusercontent.com

或者参考:

配置一个远程的,自动更新的host

然后可能需要重启系统才生效。继续执行ruby-install --latest ruby

chruby

参考:

使用chruby命令列出可用的ruby

使用chruby 3.2.2,选择3.2.2的版本

cocoapods

参考官方文档:

安装cocoapods

bash 复制代码
sudo gem install cocoapods

cocoapods镜像

原始源地址为https://github.com/CocoaPods/Specs.git

参考CocoaPods 镜像使用帮助

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

最后进入自己的工程,在自己工程的podFile第一行加上:

bash 复制代码
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

ruby镜像

移除现有的Ruby镜像

bash 复制代码
 gem sources --remove https://rubygems.org/

添加清华的镜像,参考Ruby Gems 镜像使用帮助

bash 复制代码
# 添加镜像源并移除默认源
gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/
# 列出已有源
gem sources -l
# 应该只有镜像源一个

gem

gem相关,可参考:

查看gem版本:

bash 复制代码
gem -v

遇到的问题

1.pod install时提示HTTP/2 stream 1 was not closed cleanly before end of the underlying stream

按网络上的说法解决:

bash 复制代码
git config --global http.version HTTP/1.1

其他

可参考:

相关推荐
恋猫de小郭1 个月前
CocoaPods 官宣进入维护模式,不在积极开发新功能,未来将是 Swift Package Manager 的时代
xcode·swift·cocoapods
sziitjin1 个月前
IOS 01 CocoaPods 安装与使用
xcode·cocoapods
依旧风轻1 个月前
不更新索引库, 可以直接使用新的版本么
cocoapods
恋猫de小郭1 个月前
Flutter 正在迁移到 Swift Package Manager ,未来会弃用 CocoaPods 吗?
flutter·swift·cocoapods
书弋江山2 个月前
iOS 创建一个私有的 CocoaPods 库
ios·xcode·cocoapods
WongKyunban2 个月前
iOS 开发包管理之CocoaPods
ios·xcode·cocoapods
棱镜七彩2 个月前
【网安播报】CocoaPods 曝关键漏洞,应用程序面临供应链攻击风险
xcode·cocoapods
Donkor-3 个月前
Mac电脑arm64芯片Cocoapods 的 ffi 兼容问题
macos·bug·xcode·cocoapods·ffi
星coding3 个月前
iOS 之homebrew ruby cocoapods 安装
ios·ruby·cocoapods
fendoudexiaoniao_ios3 个月前
Xcode 打包报错Command PhaseScriptExecution failed with a nonzero exit code
macos·xcode·cocoapods