Mac配置Ruby环境和安装Cocoapods

2021-04-13  本文已影响0人  弹吉他的少年

安装ruby环境

安装RVM

RVM 是一个命令行工具,可以提供一个便捷的多版本 Ruby 环境的管理和切换

1.打开终端安装rvm,安装代码

curl -L get.rvm.io | bash -s stable
image

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
image

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 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

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

大致会看到如下结果


image

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

上一篇下一篇

猜你喜欢

热点阅读