10.15.4系统
新买了个电脑在这记录下配置的基础环境
首先最好是xcode和Command Line Tools装完之后再操作
1.Homebrew
官网http://mxcl.github.com/homebrew 可以选择中文
打开终端Terminal
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
然后你会发现报错
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
解决办法有两个
1.1 修改host(/etc文件夹下,需要拷贝到其他地方才可更改)(ip地址获取网址https://www.ipaddress.com/
)
199.232.68.133 raw.githubusercontent.com
将上面内容粘贴到hosts文件最后一行,再将/etc下hosts文件替换(真心不快可能跟我网也有关系 个位数kb/s)
然后在执行
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
1.2 直接下载地址中的shell脚本(推荐,大约十分钟之内)
可以自己打开,来保证最新
https://raw.githubusercontent.com/Homebrew/install/master/install.sh (需要科学上网才能打开)
也可以用下面的代码
下载下面的sh文件然执行
https://pan.baidu.com/s/1OxuFwEP8WHEZikUBeJB_ew(提取码yguh)
执行下面命令后等着就行了
$ sh xxxx.sh
2.git
两种方案
2.1直接在terminal里输入git 回车 会自动提示你下载git
2.2 brew 安装
brew install git
3.ruby和cocopods
升级ruby(当然也可以不升级.我电脑是2.6.3 我就没升级 大于可以2.2.2 可以直接跳到3.8.0)
这里用的是rbenv
3.1 安装rbenv
$ brew install rbenv
3.2 初始化rbenv安装环境(这里会有提示)
$ rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"
3.3 我们需要执行以下命令,把 eval "$(rbenv init -)"
放到最后保存,
$ cd
$ open .bash_profile
3.4执行(可能还是会出现curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
问题)
$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
同样跟安装homebrew一样的问题
下载https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor 脚本内容
提前下载好的(官网的脚本可能会标)链接: https://pan.baidu.com/s/1fU3l5Q3Nok63CUHO1wgf7Q 提取码: fsi6
执行
$ sh xxxx.sh
terminal输出
Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20170523)
Counting installed Ruby versions: none
There aren't any Ruby versions installed under `~/.rbenv/versions'.
You can install Ruby versions like so: rbenv install 2.2.4
Checking RubyGems settings: OK
Auditing installed plugins: OK
一般出错都是
Checking for rbenv shims in PATH: NOT FOUND
这是因为rbenv init
之后没有关闭terminal或者eval "$(rbenv init -)"
没有粘贴到.bash_profile文件内
3.5更新ruby(需要等一小会)
$ rbenv install
以后需要更新ruby 只需要$ brew upgrade rbenv ruby-build
3.6 更新gem和替换源
$ sudo gem update --system
$ gem sources --remove https://rubygems.org/
$ gem sources --add https://gems.ruby-china.com/
3.7验证你的Ruby镜像是并且仅是ruby-china
$ gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
3.8.0开始安装cocoapods
(https://www.jianshu.com/p/ddc40e71210d先不要着急.这里有cocoapods的新介绍,大家可以看一下.)
$ sudo gem install -n /usr/local/bin cocoapods
3.8.1如果安装了多个Xcode使用下面的命令选择(一般需要选择最近的Xcode版本)
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
3.8.2 安装本地库(如果你是最新版的catalina系统 输出的内容可能会不一样,可以往下看)
$ pod setup
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/
3.8.3最新版的MacOS Catalina系统命令行执行pod setup命令直接结束啦(上面3.8.0连接里有讲为什么会直接结束);
我们可以直接安装本地库,也可以不去管他,在我们执行pod install
他会自动在~/.cocoapods/repos/trunk文件夹下加入我们要是使用的库文件索引而不需要我们手动安装本地库(但是有条件限制我们连不上raw.githubusercontent.com 还是需要我们 更改hosts文件(1.1中写的方法) )
手动安装本地库(是提前吧所有的库文件索引下载到本地),速度绝对快
命令行执行以下操作
git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/trunk
或者使用下面的,国内镜像,速度快些
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/trunk
目录结构见下图,如果不是就自己手动移动一下

如果还不行
// 安装最新版cocoapods
$ sudo gem install cocoapods --pre
// 移除本地master
$ sudo rm -fr ~/.cocoapods/repos/master(可能没有这个文件夹)
// 移除本地缓存
$ sudo rm -fr ~/Library/Caches/CocoaPods/
// 重新setup,如果很慢可使用问题1的解决方法(git clone)
$ pod setup --verbose
// 移除trunk
$ pod repo remove trunk
可以参考:CocoaPods|安装流程与使用(macOS-Mojave)
如果一直安装不成功请参考这里
3.8.4下载安装完成之后可执行下列命令检查是否可用(第一次使用可能要等一会)
$ pod search AFNetworking
网友评论