Mac M2 Pro安装使用Cocoapods

本文围绕在Mac Pro M2上安装使用Cocoapods展开。作者因做iOS开发需安装,升级gem和安装时遇权限问题,可通过安装ruby版本管理器解决。还介绍了SwitchHosts配置、chruby使用、cocoapods及镜像安装、ruby镜像替换等内容,同时提及遇到问题的解决办法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mac Pro M2安装使用Cocoapods

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

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

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

brew install ruby-install chruby

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

source /opt/homebrew/opt/chruby/share/chruby/chruby.sh
source /opt/homebrew/opt/chruby/share/chruby/auto.sh
chruby ruby-3.2.2

注意chruby ruby-3.2.2,这个地方的ruby版本,已你安装的版本为准

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

ruby-install --latest ruby

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

ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]

SwitchHosts

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

185.199.110.133  raw.githubusercontent.com

或者参考:

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

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

chruby

参考:

使用chruby命令列出可用的ruby
chruby

使用chruby 3.2.2,选择3.2.2的版本
chruby

cocoapods

参考官方文档:

安装cocoapods

sudo gem install cocoapods

cocoapods镜像

原始源地址为https://github.com/CocoaPods/Specs.git
参考CocoaPods 镜像使用帮助

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

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

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

ruby镜像

移除现有的Ruby镜像

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

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

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

gem

gem相关,可参考:

查看gem版本:

gem -v

遇到的问题

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

error
按网络上的说法解决:

git config --global http.version HTTP/1.1

2.git clone时的各种出错
猜测是由于国内的网络环境造成的,所以可以给git配置代理

查看git代理:

git config --global --get http.proxy
git config --global --get https.proxy

设置git代理:

git config --global http.proxy "http://127.0.0.1:7890"
git config --global https.proxy "https://127.0.0.1:7890"

取消设置:

git config --global --unset http.proxy
git config --global --unset https.proxy

其他

可参考:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值