欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

树莓派安装Homebrew全过程

程序员文章站 2022-06-04 19:50:13
...

首先,各大Linux官方一般都有自己的包管理器,一般首选官方的包管理器。

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

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

sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/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/Linuxbrew/install/master/install.sh -O 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://raw.githubusercontent.com/Linuxbrew/install/master/install.sh,看到的内容全部复制下来,创建一个文件命名为install.sh,把复制的内容全部粘贴再这里面。

  2. 更改安装检查脚本:

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

    exec ruby -e "`curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install`" "[email protected]"
    

    我们需要更改为:

    exec ruby "install_linux.rb" "[email protected]"
    
  3. 下载安装文件:

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

      wget https://raw.githubusercontent.com/Linuxbrew/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://raw.githubusercontent.com/Linuxbrew/install/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/linuxbrew/.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
    
相关标签: linux