Mac M1搭建RVM、Ruby、Cocoapods环境

2,045 阅读2分钟

安装Brew

执行以下语句,选择一个安装brew的源(我选的清华源)

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

image.png

安装完成后可以继续安装Core、Cask等

image.png

配置后续使用brew 安装软件时使用的原 image.png

可以看到,速度还是挺快的

image.png

使用brew安装cmake

brew install cmake

使用brew安装python

brew install python

使用brew安装ninja

brew install ninja

安装 Apple Command Line

xcode-select --install

安装ruby

查看系统自带的ruby版本

ruby -v

image.png

安装rvm,使用rvm管理ruby

安装rvm命令 curl -L get.rvm.io | bash -s stable

立即更新,让shell的当前session生效 // zsh,新版系统默认shell都是zsh source ~/.zshrc source ~/.profile

使用rvm查看可安装的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[.10]
[ruby-]2.5[.8]
[ruby-]2.6[.6]
[ruby-]2.7[.2]
[ruby-]3[.0.0]
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.14.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[.20]
rbx-5[.0]
rbx-head

# TruffleRuby
truffleruby[-20.3.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-2[.1.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

修改gem源

gem source -l
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/

安装最新版ruby并设置为默认

rvm install 3.0.0

执行过程中可能遇到以下报错 image.png

解决办法如下

1. brew uninstall --ignore-dependencies openssl@3

2. rm -rf /usr/local/etc/openssl@1.1

3. brew reinstall openssl@1.1

4. rvm install 3.0.0

设置ruby3.0.0为默认版本。注意这并不会覆盖系统中的ruby版本

rvm use 3.0.0 --default

安装 cocoapods

sudo gem install -n /usr/local/bin cocoapods

查看pod版本

pod --version

pod 1.13 之后会遇到这个报错 image.png

解决办法

限制为 activesupport (7.0.8) 的最新版本 不要执行这个方法 // gem 'activesupport', '~> 7.0', '<= 7.0.8'

  1. sudo gem install activesupport -v 7.0.8 安装7.0.8版本
  2. gem list | grep activesupport查看已安装的ativesupport版本
  3. sudo gem uninstall activesupport删除7.0.8外的其他版本

使用pod初始化工程并更新repo spec

pod setup
// 更新repo spec
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/trunk

参考资料

juejin.cn/post/700290… juejin.cn/post/708628… zhuanlan.zhihu.com/p/111014448 zhuanlan.zhihu.com/p/604160866 www.jianshu.com/p/50ae4af5d… blog.csdn.net/xyanq2222/a… blog.csdn.net/xyanq2222/a…