树莓派安装Homebrew全过程

Tony 219m2020-12-081455 次点击1 人感谢
https://blog.csdn.net/weixin_41136293/article/details/104496971
首先,各大Linux官方一般都有自己的包管理器,一般首选官方的包管理器。

安装一些依赖:`sudo apt install ruby build-essential`

官方的给出的一键安装命令:

```
/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. 下载安装检查脚本:

如果有`wget`,可以尝试使用`wget`下载:

```
wget https://raw.githubusercontent.com/Homebrew/install/master/install.sh
```

如果出现错误:
```
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.228.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.228.133|:443... failed: Connection refused.
```

请使用下面的方法!

直接使用浏览器打开链接`https://github.com/Homebrew/install/blob/master/install.sh `,看到的内容全部复制下来,创建一个文件命名为`install.sh`,把复制的内容全部粘贴再这里面。

2. 更改安装检查脚本:

在安装检查脚本里面有一行:

```
exec ruby -e "`curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install`" "$@"
```

我们需要更改为:

```
exec ruby "install_linux.rb" "$@"
```

3. 下载安装文件:

如果有`wget`,可以尝试使用`wget`下载:

```
wget https://raw.githubusercontent.com/Homebrew/install/master/install -O install_linux.rb
```

如果出现错误:

```
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.228.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.228.133|:443... failed: Connection refused.
```

请使用下面的方法!

直接使用浏览器打开链接`https://github.com/Homebrew/install/blob/master/install`,看到的内容全部复制下来,创建一个文件命名为`install_linux.rb`,把复制的内容全部粘贴再这里面。

4. 更改安装文件:

修改官方文件里面的源:

​ 在`BREW_REPO = "https://github.com/Homebrew/brew".freeze`前加`#`号

​ 在下方加入一行:`BREW_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git".freeze`

接下来给安装检查文件加上执行权限:`chmod +x install.sh`,然后执行`./install.sh`

等待安装,不出意外就会看见:

```
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==> Tapping homebrew/core
Cloning into '/home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core'...
```

下载仓库的地址在国外,下载会比较慢,我们可以手动下载。

首先使用组合键`CTRL+C`关闭安装过程,

创建目录:

```
mkdir /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew,
```

进入目录:

```
cd /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew。
```

然后执行:

```
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
```

回到原来目录:`cd -`

再次执行:`./install.sh`

执行后会提示:

```
- Configure Homebrew in your ~/.profile by running
echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >>~/.profile
- Add Homebrew to your PATH
eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
- We recommend that you install GCC by running:
brew install gcc
- Run `brew help` to get started
- Further documentation:
https://docs.brew.sh
Warning: /home/linuxbrew/.linuxbrew/bin is not in your PATH.
```

如果出现了这个`Warning`则需要手动进行一些操作:

- 如果是`bash`用户:

编辑`.profile或者.bash_profile`,添加一行:`eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)`

- 如果是`zsh`用户:

编辑.zhcrc,添加一行`eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)`
重启一下或者直接在命令行执行:`eval $(/home/homebrew/.linuxbrew/bin/brew shellenv)`,就可以正常使用brew。

使用过程中更换为国内的源使用起来更加舒适

更换brew的源为清华源:
```
git -C /home/linuxbrew/.linuxbrew/Homebrew remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-cask remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
git -C /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-cask-fonts remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-cask-drivers remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
brew update
```

更改`bintray`镜像:

临时更改:`export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles`

长期更改:

- `bash`用户

```
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.profile
```

- `zsh`用户

```
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
```
收藏 ♥ 感谢
暂无回复

登录注册 后可回复。




› 相关内容关注微信公众号