安裝ruby環境
安裝RVM
RVM 是一個命令行工具,可以提供一個便捷的多版本 Ruby 環境的管理和切換
1.打開終端安裝rvm,安裝代碼
curl -L get.rvm.io | bash -s stable
2.查看rvm是否安裝成功
rvm -v
備注:如果出現查找不到的情況,可以關閉終端再次打開
成功會看到如下:
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
安裝Homebrew
Mac上的軟件包管理工具
1.安裝代碼
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
備注:這里需要輸入你的電腦密碼進行安裝,然后就是漫長的等待。最好掛個代理下載的快。
安裝Ruby環境
1.列出已有的ruby:
rvm list known
2.安裝
brew rvm install 3.0.0 # 我選擇安裝的最新版本
成功大致如下:
ruby-3.0.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-3.0.0 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
安裝成功后,我們讓其在本地環境中生效:
rbenv shell 3.0.0
3.查詢已經安裝的ruby
rvm list
4.設置 Ruby 版本
RVM 裝好以后,需要執行下面的命令將指定版本的 Ruby 設置為系統默認版本
rvm 3.0.0 --default
5.查看是否設置正確
ruby -v
大致如下:ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
6.切換Source源,替換Ruby源
因為Ruby的默認源使用的是cocoapods.org,國內訪問這個網址有時候會有問題,通常解決方案是將遠替換成國內Ruby鏡像
刪除原有源
gem source -r https://rubygems.org/
更新新源
gem source -a https://gems.ruby-china.com
驗證是否替換成功
gem sources -l
輸出如下結果表示替換成功:
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
7.更新升級Gem版本,Gem是來管理Ruby標準包
sudo gem update --system
mac OS 10.11之后
sudo gem update -n /usr/local/bin —system
安裝Cocoapods
第一種:使用Homebrew安裝,直接終端輸入:
brew install cocoapods
成功大致如下:
Warning: Treating cocoapods as a formula. For the cask, use homebrew/cask/cocoapods
==> **Downloading https://ghcr.io/v2/homebrew/core/cocoapods/manifests/1.11.2_1**
Already downloaded: /Users/aba/Library/Caches/Homebrew/downloads/d6cda7b7f4a10f3f41627eef16cb4deb95fa5a828a64ad48b98bd46db3d6e97c--cocoapods-1.11.2_1.bottle_manifest.json
==> **Downloading https://ghcr.io/v2/homebrew/core/cocoapods/blobs/sha256:4eb89ca73f311a1e0c52a0b72d22**
Already downloaded: /Users/aba/Library/Caches/Homebrew/downloads/738e83a462b9a0cec78a37271267ae01966cc849a57449726dee8f426fa8739f--cocoapods--1.11.2_1.monterey.bottle.tar.gz
==> **Reinstalling** **cocoapods******
==> **Pouring cocoapods--1.11.2_1.monterey.bottle.tar.gz**
?? /usr/local/Cellar/cocoapods/1.11.2_1: 14,105 files, 29.8MB
查看cocoapods版本
pod --version
1.11.2 # 我的cocoapods版本
檢查更新
- 更新brew倉庫,原理就是從github上拉去一下brew-core的最新代碼
brew update
- 檢查更新
brew outdated cocoapods # cocoapods (1.9.1) < 1.9.3
更新cocoapods
brew upgrade cocoapods
第二種:采用Gem安裝,直接終端輸入:
1.安裝cocoapods
sudo gem install cocoapods
mac OS 10.11之后
sudo gem install -n /usr/local/bin cocoapods
成功大致如下:
Fetching cocoapods-1.11.2.gem
Successfully installed cocoapods-1.11.2
Parsing documentation for cocoapods-1.11.2
Installing ri documentation for cocoapods-1.11.2
Done installing documentation for cocoapods after 2 seconds
1 gem installed
如果出現如下情況
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
解決方案:
sudo gem install cocoapods -n /usr/local/bin
2.將Github上的Pod托管的Podspec索引都安裝到本地
pod setup
- 如果上述命令執行后什么都沒做,則自己手動添加索引庫
pod repo add master https://github.com/CocoaPods/Specs.git
如果出現該問題,克隆失敗
Cloning spec repo `master` from `https://github.com/CocoaPods/Specs.git`
[!] /usr/local/bin/git clone https://github.com/CocoaPods/Specs.git -- master
\
正克隆到 'master'...
fatal: 無法訪問 'https://github.com/CocoaPods/Specs.git/':LibreSSL SSL_connect: Operation timed out in connection to github.com:443
- 方案一:該問題就說明網絡不好,則再次執行上述命令
- 方案二:Cocoapods的GitHub下載zip,然后解壓到
~/.cocoapods/repos/master
目錄下
備注:command + G,輸入文件目錄
3.查看索引是否配置成功
pod repo list
cocoapods
- Type: git (remotes/origin/master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/aba/.cocoapods/repos/cocoapods
master
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/aba/.cocoapods/repos/master
卸載CocoaPods
移除pod組件
1.查看pod位置
which pod
2.刪除
sudo rm -rf 路徑地址
備注:-rf
表示遞歸和強制,切記不要亂使用rm -rf /
,否則你的系統就全沒了,哈哈哈!??!
3.查看是否卸載成功
pod version
移除RubyGems中的CocoaPods程序包
1.查看gem當中的程序包
gem list
大致會看到如下結果
2.移除程序包
sudo gem uninstall cocoapods
移除指定程序包
sudo gem uninstall cocoapods -v 0、1.9.3
安裝Xcode插件
插件包Alcatraz
1.安裝插件包
mkdir -p ~/Library/Application\Support/Developer/Shared/Xcode/Plug-ins;curl -L http://git.io/lOQWeA | tar xvz -C ~/Library/Application\Support/Developer/Shared/Xcode/Plug-ins
2.卸載
rm -rf ~/Library/Application\Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcpluginrm -rf ~/Library/Application\Support/Alcatraz
GitHub配置SSH keys
生成SSH keys
1.打開終端執行如下命令:
ssh-keygen -t rsa -C "your_email@example.com"
2.配置密碼流程,不過我一般都不會設置密碼,麻煩。
如果設置了密碼每次提交代碼都要讓你輸入密碼,因此直接回車完事
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/mac/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/mac/.ssh/id_rsa
Your public key has been saved in /Users/mac/.ssh/id_rsa.pub
3.獲取SSH key
pbcopy < ~/.ssh/id_rsa.pub
此時已將密鑰復制在剪切板,直接去GitHub里面Settings
->SSH and GPG keys
-> New SSH key
-> Key
粘貼進去保存即可。
4.查看本地SSH密鑰
ls -al ~/.ssh
5.刪除本地SSH密鑰
rm ~/.ssh/被刪除密鑰名
例如:rm ~/.ssh/id_ecdsa.pub