打開終端:>_
1舅桩、查看當前Ruby版本
執(zhí)行:ruby -v執(zhí)行結果:ruby 2.6.3p62(2019-04-16 revision 67580)[universal.x86_64-darwin20]
2殴穴、升級Ruby環(huán)境俄精,首先需要安裝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绳锅,執(zhí)行以下命令查看
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、執(zhí)行以上命令后
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“
執(zhí)行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 tyrone.lin@ui.com? admin? 96? 4 13 16:34 .
drwxr-xr-x? 4 tyrone.lin@ui.com? admin? 128? 4 14 11:31 ..
drwxr-xr-x? 12 tyrone.lin@ui.com? admin? 384? 4 14 11:44 .git
執(zhí)行:
% git fetch --prune origin % git pull --rebase origin master From https://mirrors.ustc.edu.cn/homebrew-core * branch ?master? ? -> FETCH_HEAD
成功后執(zhí)行%?
brew update
Already up-to-date.
之后便可正常執(zhí)行其他命令了
eg. % brew install rbenv ruby-build