打开终端:>_
1、查看当前Ruby版本
执行:ruby -v执行结果:ruby 2.6.3p62(2019-04-16 revision 67580)[universal.x86_64-darwin20]
2、升级Ruby环境,首先需要安装rvm(第一步要下载一些东西等两分钟左右)
curl -L get.rvm.io | bash -s stable source ~/.bashrcsource ~/.bash_profile
3、查看rvm版本
rvm -v
显示如下(或者是其他版本)
rvm 1.29.12(latest)by Michal Papis,Piotr Kuczynski,Wayne E. Seguin [https://rvm.io]
4、列出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.....
5、安装一个ruby版本(这里我选择的是3.0.0版本,当然你也可以选择其他的)
rvm install 3.0.0
// 注意:安装过程中需要两次按下 Enter 键, 第二次按下后需要输入电脑访问密码(不可见,只管输入就行);// 如果你电脑没有安装Xcode和Command Line Tools for Xcode以及Homebrew 会自动下载安装,建议提前安装这三者.
这里很多小伙伴会遇到错误,大部分是因为没有安装Homebrew造成,所以所以所以要提前安装比较好
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
6、设置为默认版本
rvm use 3.0.0 --default
7、更换源
sudo gem update--systemgem
sources--removehttps://rubygems.org/gem
sources--addhttps://gems.ruby-china.com/
8、为了验证你的Ruby镜像是并且仅是ruby-china,执行以下命令查看
gem sources -l
如果是以下结果说明正确,如果有其他的请自行百度解决
***CURRENT SOURCES***https://gems.ruby-china.com/
9、这时候才正式开始安装CocoaPods
sudo gem install -n /usr/local/bin cocoapods
10、如果安装了多个Xcode使用下面的命令选择(一般需要选择最近的Xcode版本)
sudo xcode-select-switch/Applications/Xcode.app/Contents/Developer
11、安装本地库
pod setup
12、执行以上命令后
Setting up CocoaPods master repo $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress Cloning into 'master'... remote: Counting objects: 1879515, done. remote: Compressing objects: 100% (321/321), done. Receiving objects: 21% (404525/1879515), 73.70 MiB | 22.00 KiB/
rvm install 3.0.0 提示需要更新时的报错 按以下操作
brew update 报错 “fatal: Could not resolve HEAD to a revision“
执行brew update命令时:
% brew update
error: Not a valid ref: refs/remotes/origin/master
fatal: Could not resolve HEAD to a revision
Already up-to-date.
解决
% brew update --verbose
% brew update -verbose
Checking if we need to fetch /opt/homebrew...
Checking if we need to fetch /opt/homebrew/Library/Taps/homebrew/homebrew-cask...
Fetching /opt/homebrew...
Checking if we need to fetch /opt/homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /opt/homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /opt/homebrew/Library/Taps/homebrew/homebrew-cask...
fatal: unable to access 'https://github.com/Homebrew/homebrew-cask/': Failed to connect to github.com port 443: Operation timed out
Error: Fetching /opt/homebrew/Library/Taps/homebrew/homebrew-cask failed!
Updating /opt/homebrew...
Branch 'master' set up to track remote branch 'master' from 'origin'.
Switched to and reset branch 'master'
Your branch is up to date with 'origin/master'.
Switched to and reset branch 'stable'
Current branch stable is up to date.
Updating /opt/homebrew/Library/Taps/homebrew/homebrew-core...
fatal: Could not resolve HEAD to a revision
打开报错路径:
% cd /opt/homebrew/Library/Taps/homebrew/homebrew-core
% ls -al
total 0
drwxr-xr-x 3 [email protected] admin 96 4 13 16:34 .
drwxr-xr-x 4 [email protected] admin 128 4 14 11:31 ..
drwxr-xr-x 12 [email protected] admin 384 4 14 11:44 .git
执行:
% git fetch --prune origin % git pull --rebase origin master From https://mirrors.ustc.edu.cn/homebrew-core * branch master -> FETCH_HEAD
成功后执行%
brew update
Already up-to-date.
之后便可正常执行其他命令了
eg. % brew install rbenv ruby-build