近日用新MacBook(M1)安装了 cocoapods环境,一堆坑,整的我不要不要的,搞个通宵,写个文章记录一下!
安装后的环境版本(小括号中 对应终端查看命令):
Homebrew 2.7.5 (brew -v)
Rvm: 1.29.12 (rvm -v)
Ruby: 2.6.3p62 (ruby -v)
Cocoapod: 1.10.1 (pod --version)>>>开始进入正题:
前菜:先查看Xcode下是否选中,不能空白:
image一、检查Homebrew环境:
查看命令:
brew -v
如果提示:zsh: command not found: brew 执行安装命令:(来自Homebrew官网)
**/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"**
安装homebrew报错:curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443
通过搜索引擎找了很多解决方案,有的说是DNS污染,需要配置host,通过域名反查IP后写入hosts文件后,还是不能有效解决,最终采用国内镜像源安装。
yamol@YamoldeMacBook-Pro ~ % /bin/bash -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
开始执行Brew自动安装程序
[cunkai.wang@foxmail.com]
['2021-12-15 06:51:31']['12.1']
https://zhuanlan.zhihu.com/p/111014448
请选择一个下载镜像,例如中科大,输入1回车。
源有时候不稳定,如果git克隆报错重新运行脚本选择源。cask非必须,有部分人需要。
1、中科大下载源 2、清华大学下载源 3、北京外国语大学下载源 4、腾讯下载源(不推荐) 5、阿里巴巴下载源(不推荐 缺少cask源)
请输入序号: 1
你选择了中国科学技术大学下载源
!!!此脚本将要删除之前的brew(包括它下载的软件),请自行备份。
->是否现在开始执行脚本(N/Y) y
--> 脚本开始执行
Mac os设置开机密码方法:
(设置开机密码:在左上角苹果图标->系统偏好设置->用户与群组->更改密码)
(如果提示This incident will be reported. 在用户与群组中查看是否管理员)
==> 通过命令删除之前的brew、创建一个新的Homebrew文件夹
请输入开机密码,输入过程不显示,输入完后回车
Password:
开始执行
---备份要删除的/usr/local/Homebrew到系统桌面....
---/usr/local/Homebrew 备份完成
-> 创建文件夹 /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /usr/local/Homebrew
此步骤成功
运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown yamol /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew
---备份要删除的/Users/yamol/Library/Caches/Homebrew到系统桌面....
---/Users/yamol/Library/Caches/Homebrew 备份完成
git version 2.32.0 (Apple Git-132)
下载速度觉得慢可以ctrl+c或control+c重新运行脚本选择下载源
==> 克隆Homebrew基本文件
未发现Git代理(属于正常状态)
Cloning into '/usr/local/Homebrew'...
remote: Enumerating objects: 206378, done.
remote: Total 206378 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (206378/206378), 54.24 MiB | 10.78 MiB/s, done.
Resolving deltas: 100% (153617/153617), done.
Updating files: 100% (2720/2720), done.
此步骤成功
--创建Brew所需要的目录
运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R yamol:admin /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /Users/yamol/Library/Caches/Homebrew
运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /Users/yamol/Library/Caches/Homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R yamol /Users/yamol/Library/Caches/Homebrew
--依赖目录脚本运行完成
==> 创建brew的替身
==> 克隆Homebrew Core
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 1110596, done.
remote: Total 1110596 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1110596/1110596), 458.14 MiB | 10.75 MiB/s, done.
Resolving deltas: 59% (458306/772573)
开始下载后就不需要你操作,静静的等待安装完就行了……
完成后执行 brew -v 提示如下代表安装成功:
Homebrew 2.7.5 Homebrew/homebrew-core (git revision 18218; last commit 2021-01-28)12
二、安装RVM:
查看命令:
rvm -v
如果提示:zsh: command not found: rvm
下载安装:
Holothurian-iMac ~ % git clone https://github.com/rvm/rvm.git
Cloning into 'rvm'...
remote: Enumerating objects: 92, done.
remote: Counting objects: 100% (92/92), done.
remote: Compressing objects: 100% (62/62), done.
remote: Total 59450 (delta 57), reused 53 (delta 29), pack-reused 59358
Receiving objects: 100% (59450/59450), 20.07 MiB | 30.00 KiB/s, done.
Resolving deltas: 100% (38714/38714), done.
下载完之后、根据路径/Users/用户名,找到rvm文件夹下,找到 /bin/rvm-installer中 rvm-installer双击,然后会出现下面的内容:
Last login: Fri Aug 7 15:42:51 on ttys001
/Users/holothurian/rvm/binscripts/rvm-installer ; exit;
Holothurian-iMac ~ % /Users/holothurian/rvm/binscripts/rvm-installer ; exit;
Downloading https://github.com/rvm/rvm/archive/master.tar.gz
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
Could not download 'https://github.com/rvm/rvm/archive/master.tar.gz'.
curl returned status '56'.
Downloading https://bitbucket.org/mpapis/rvm/get/master.tar.gz
Installing RVM to /Users/holothurian/.rvm/
Adding rvm PATH line to /Users/holothurian/.profile /Users/holothurian/.mkshrc /Users/holothurian/.bashrc /Users/holothurian/.zshrc.
Adding rvm loading line to /Users/holothurian/.profile /Users/holothurian/.bash_profile /Users/holothurian/.zlogin.
Installation of RVM in /Users/holothurian/.rvm/ is almost complete:
* To start using RVM you need to run `source /Users/holothurian/.rvm/scripts/rvm`
in all your open shell windows, in rare cases you need to reopen all shell windows.
Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.
👉 Donate: https://opencollective.com/rvm/donate
[进程已完成]
安装完了rvm之后、还需要配置环境变量
Holothurian-iMac ~ % vi ~/.bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Holothurian-iMac ~ % source ~/.rvm/scripts/rvm
查看当前版本
Holothurian-iMac ~ % rvm -v
rvm 1.29.10 (master) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
Holothurian-iMac ~ %
三、保证 ruby 版本要 > 2.2.2
用 RVM 安装 Ruby 环境:
列出已知的ruby版本 : rvm list known
安装一个版本 rvm install 2.6.3
** (可不看内容:**
①若出现问题,网上搜报错容易解决
②查询已经安装的ruby** rvm list**
③卸载一个已安装版本rvm remove 2.x.x
④RVM 装好以后,需要执行下面的命令将指定版本的 Ruby 设置为系统默认版本rvm 2.6.3 --default
)
四、更换镜像源
sudo gem update --system
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
查看 gem sources -l 提示成功:
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
五、安装CocoaPods:
新版的 CocoaPods 不允许用pod repo add直接添加master库了,但是依然可以:
cd ~/.cocoapods/repos
$ pod repo remove master
$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master
(完事之后记得remove trunk ,执行下面的命令pod repo remove trunk如果不执行remove还可能会出现 CDN:trunk 的问题。 执行其他命令的过程中可能会生成trunk文件,和master同路径目录下。)
最后进入自己的工程,在自己工程的podFile第一行加上:
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
文章参考了:
CocoaPods 最新系统安装 2021-01-28(包含M1)
感谢!
网友评论