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

其他

可参考:

相关推荐
Keya20 天前
解决 pod install 警告信息显示不完全的方法
ios·xcode·cocoapods
帅次21 天前
【iOS设计模式】深入理解MVC架构 - 重构你的第一个App
ios·swiftui·objective-c·iphone·swift·safari·cocoapods
@PHARAOH22 天前
WHAT - 依赖管理工具 CocoaPods
xcode·cocoapods
gavin carter1 个月前
一台电脑管理多个cocoapods账号
xcode·cocoapods
明似水1 个月前
解决 Ruby Gem “rexml“ 版本不兼容问题 (CocoaPods/Firebase 相关错误)
开发语言·ruby·cocoapods
survivorsfyh2 个月前
Xcode 16 集成 cocoapods 报错
macos·xcode·cocoapods
survivorsfyh2 个月前
error: Sandbox: rsync(17136) deny(1) file-write-create
xcode·cocoapods
龙之吻2 个月前
iOS 使用CocoaPods 添加Alamofire 提示错误的问题
ios·xcode·cocoapods
Jim-zf2 个月前
VScode ios 模拟器安装cocoapods
ios·xcode·cocoapods
[奋斗不止]3 个月前
MacOS 安装 cocoapods
macos·cocoapods·mac cocoapods·macos cocoapods