为了防止万恶的资本主义侵蚀,我们有的开发工具比如Homebrewcocoapods等受到牵连,所以在没有梯子的情况下,不妨试试这样安装

一、Homebrew

Homebrew 是一款自由及开放源代码的软件包管理系统,用以简化 macOS 系统上的软件安装过程。它拥有安装、卸载、更新、查看、搜索等很多实用的功能,通过简单的一条指令,就可以实现包管理,十分方便快捷。目前支持macOS和linux系统。主要有四个部分组成: brewhomebrew-corehomebrew-caskhomebrew-bottles

组成部分作用
brewHomebrew源代码仓库
homebrew-coreHomebrew核心库
homebrew-cask提供macOS应用和大型二进制文件的安装
homebrew-bottles预编译二进制软件包

在执行官方命令的安装过程中,经常能遇到以下timed out的连接错误

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Operation timed out

这时候可以用国内镜像方式安装

1.1、安装

1.1.1、执行安装脚本

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"

执行后创建了环境变量,但是在下载homebrew-core等文件时可能还是会卡住,卡住的话,可以按住Control + C中断执行,然后执行后面下面操作

1.1.2、下载homebrew-core

cd "$(brew --repo)/Library/Taps/"
mkdir homebrew && cd homebrew
git clone git://mirrors.ustc.edu.cn/homebrew-core.git

1.1.3、下载homebrew-cask

cd "$(brew --repo)/Library/Taps/"
cd homebrew
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git

1.1.4、继续执行安装

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"

1.1.5、更新

brew update

1.2、Homebrew更换使用阿里镜像

Bash 终端配置

1.2.1、替换brew.git:

cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

1.2.2、替换homebrew-core.git:

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

1.2.3、应用生效

brew update

1.2.4、替换homebrew-bottles

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

Zsh 终端配置

1.2.5、替换brew.git:

cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

1.2.6、替换homebrew-core.git:

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

1.2.7、应用生效

brew update

1.2.8、替换homebrew-bottles

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

二、替换Ruby Gems 镜像

Ruby Gems 是 Ruby 的一个包管理器,它提供一个分发 Ruby 程序和库的标准格式,还提供一个管理程序包安装的工具。旨在方便地管理 gem 安装的工具,以及用于分发 gem 的服务器。这类似于Ubuntu下的apt-get, Centosyum

在安装cocoapod时,运行的命令sudo gem install -n /usr/local/bin cocoapods就是用的这个

2.1、镜像替换为阿里云

2.1.1、查找默认源

gem sources

2.1.2、移除默认源

gem sources --remove https://rubygems.org/

2.1.3、添加新源

gem sources -a https://mirrors.aliyun.com/rubygems/

三、替换PyPI 镜像

PyPI (Python Package Index) 是 Python 编程语言的软件存储库。开发者可以通过 PyPI 查找和安装由 Python 社区开发和共享的软件,也可以将自己开发的库上传至 PyPI 。

例如运行pip install powerline-status --user安装powerline时就用到这个,如果是python3,运行的是pip3的命令

运行下面命令更新为阿里云镜像

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ 

如果是python3的版本,可以运行

pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/ 

四、总结

现在阿里出了不错的镜像网站汇总:https://developer.aliyun.com/mirror/。可以看看有没有刚好自己用到的

另外可以把 /etc/hosts中配置下面的解析,防止GitHub的域名解析被污染的可能

199.232.28.133 raw.githubusercontent.com 

☟☟可点击下方广告支持一下☟☟

最后修改:2020 年 04 月 23 日
请我喝杯可乐,请随意打赏: ☞已打赏列表