美文网首页MacOS
Mac全自动安装brew一键配置国内镜像源

Mac全自动安装brew一键配置国内镜像源

作者: 文档随手记 | 来源:发表于2022-09-20 16:59 被阅读0次

    安装homebrew

    官网方法:macOS(或 Linux)缺失的软件包的管理器 — Homebrew

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    

    安装brew

    如果已经安装会顺便卸载就得brew
    执行:

    /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
    

    需要输入密码授权一下,并且会让你选择镜像源,我选择的中科大的,1。
    原因可以看一下中科大源,官方的介绍:


    image.png

    脚本输出如下:

    tank@tankerdeMacBook-Pro ~ % /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
     
                  开始执行Brew自动安装程序
                 [cunkai.wang@foxmail.com]
               [2020-10-17 14:34:27][10.15]
           https://zhuanlan.zhihu.com/p/111014448
     
     
    请选择一个下载镜像,例如中科大,输入1回车。
    源有时候不稳定,如果git克隆报错重新运行脚本选择源。cask非必须,有部分人需要。
    1、中科大下载源 2、清华大学下载源 3、北京外国语大学下载源 4、腾讯下载源(不显示下载进度) 5、阿里巴巴下载源(缺少cask源)
    请输入序号: 1
     
      你选择了中国科学技术大学下载源
     
    !!!此脚本将要删除之前的brew(包括它下载的软件),请自行备份。
    ->是否现在开始执行脚本(N/Y)Y
     
    --> 脚本开始执行
    ==> 通过命令删除之前的brew、创建一个新的Homebrew文件夹
    (设置开机密码:在左上角苹果图标->系统偏好设置->"用户与群组"->更改密码)
    (如果提示This incident will be reported. 在"用户与群组"中查看是否管理员)
    请输入开机密码,输入过程不显示,输入完后回车
    Password:
    开始执行
    -> 创建文件夹 /usr/local/Homebrew
    此步骤成功
    -> 创建文件夹 /usr/local/Caskroom
    此步骤成功
    -> 创建文件夹 /usr/local/Cellar
    此步骤成功
    -> 创建文件夹 /usr/local/var/homebrew
    此步骤成功
    -> 创建文件夹 /usr/local/etc
    此步骤成功
    -> 创建文件夹 /usr/local/include
    此步骤成功
    -> 创建文件夹 /usr/local/lib
    此步骤成功
    -> 创建文件夹 /usr/local/sbin
    此步骤成功
    -> 创建文件夹 /usr/local/opt
    此步骤成功
    -> 创建文件夹 /usr/local/share/zsh
    此步骤成功
    -> 创建文件夹 /usr/local/share/zsh/site-functions
    此步骤成功
    -> 创建文件夹 /usr/local/var/homebrew/linked
    此步骤成功
    -> 创建文件夹 /usr/local/Frameworks
    此步骤成功
    git version 2.24.3 (Apple Git-128)
     
    下载速度觉得慢可以ctrl+c或control+c重新运行脚本选择下载源
    ==> 克隆Homebrew基本文件(32M+)
     
    未发现Git代理(属于正常状态)
    Cloning into '/usr/local/Homebrew'...
    remote: Enumerating objects: 164443, done.
    remote: Total 164443 (delta 0), reused 0 (delta 0)
    Receiving objects: 100% (164443/164443), 40.59 MiB | 25.69 MiB/s, done.
    Resolving deltas: 100% (122247/122247), done.
    此步骤成功
    ==> 创建brew的替身
    此步骤成功
    ==> 克隆Homebrew Core(224M+)
    此处如果显示Password表示需要再次输入开机密码,输入完后回车
    Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
    remote: Enumerating objects: 806736, done.
    remote: Total 806736 (delta 0), reused 0 (delta 0)
    Receiving objects: 100% (806736/806736), 320.87 MiB | 29.34 MiB/s, done.
    Resolving deltas: 100% (542292/542292), done.
    此步骤成功
    ==> 克隆Homebrew Cask(248M+) 类似AppStore
    此处如果显示Password表示需要再次输入开机密码,输入完后回车
    Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
    remote: Enumerating objects: 485786, done.
    remote: Total 485786 (delta 0), reused 0 (delta 0)B | 15.37 MiB/s
    Receiving objects: 100% (485786/485786), 220.15 MiB | 22.69 MiB/s, done.
    Resolving deltas: 100% (345538/345538), done.
    此步骤成功
    ==> 配置国内镜像源HOMEBREW BOTTLE
    此步骤成功
     
    ==> 安装完成,brew版本
     
    10.15
    brew -v
     
    Homebrew 2.5.6-65-g1670883-dirty
    Homebrew/homebrew-core (git revision 73588; last commit 2020-10-17)
    Homebrew/homebrew-cask (git revision 022d57; last commit 2020-10-17)
    Brew前期配置成功
     
    ==> brew update
     
    ==> Homebrew has enabled anonymous aggregate formula and cask analytics.
    Read the analytics documentation (and how to opt-out) here:
      https://docs.brew.sh/Analytics
    No analytics have been recorded yet (or will be during this `brew` run).
     
    ==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
      https://github.com/Homebrew/brew#donations
    Already up-to-date.
     
            上一句如果提示Already up-to-date表示成功
                Brew自动安装程序运行完成
                  国内地址已经配置完成
     
                    初步介绍几个brew命令
     
            本地软件库列表:brew ls
            查找软件:brew search google(其中google替换为要查找的软件关键字)
            查看brew版本:brew -v  更新brew版本:brew update
     
    现在可以输入命令open ~/.zshrc -e 或者 open ~/.bash_profile -e 整理一下重复的语句(运行 echo $SHELL 可以查看应该打开那一个文件修改)
     
            https://zhuanlan.zhihu.com/p/111014448  欢迎来给点个赞
     
    tank@tankerdeMacBook-Pro ~ % brew -v
    Homebrew 2.5.6-65-g1670883-dirty
    Homebrew/homebrew-core (git revision 73588; last commit 2020-10-17)
    Homebrew/homebrew-cask (git revision 022d57; last commit 2020-10-17)
    tank@tankerdeMacBook-Pro ~ % brew ls
    tank@tankerdeMacBook-Pro ~ % brew search google
    ==> Formulae
    aws-google-auth                 google-authenticator-libpam     google-benchmark                google-go                       google-java-format              google-sparsehash               google-sql-tool                 googler
    ==> Casks
    google-ads-editor                                  google-cloud-sdk                                   google-japanese-ime                                marshallofsound-google-play-music-player           homebrew/cask-versions/google-japanese-ime-dev
    google-analytics-opt-out                           google-drive-file-stream                           google-photos-backup-and-sync                      moefe-google-translate
    google-backup-and-sync                             google-earth-pro                                   google-trends                                      homebrew/cask-versions/google-chrome-beta
    google-chat                                        google-featured-photos                             google-web-designer                                homebrew/cask-versions/google-chrome-canary
    google-chrome                                      google-hangouts                                    googleappengine                                    homebrew/cask-versions/google-chrome-dev
    tank@tankerdeMacBook-Pro ~ % brew update
    Already up-to-date.
    

    安装完成,验证一下源:

    tank@tankerdeMacBook-Pro homebrew-core % cd "$(brew --repo)"
    tank@tankerdeMacBook-Pro Homebrew % git remote -v
    origin  https://mirrors.ustc.edu.cn/brew.git (fetch)
    origin  https://mirrors.ustc.edu.cn/brew.git (push)
    tank@tankerdeMacBook-Pro Homebrew % cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    tank@tankerdeMacBook-Pro homebrew-core % git remote -v
    origin  https://mirrors.ustc.edu.cn/homebrew-core.git (fetch)
    origin  https://mirrors.ustc.edu.cn/homebrew-core.git (push)
    tank@tankerdeMacBook-Pro homebrew-core % cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
    tank@tankerdeMacBook-Pro homebrew-cask % git remote -v
    origin  https://mirrors.ustc.edu.cn/homebrew-cask.git (fetch)
    origin  https://mirrors.ustc.edu.cn/homebrew-cask.git (push)
    tank@tankerdeMacBook-Pro homebrew-cask %
    

    Mac 下 brew 切换为国内源

    简介

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


    image.png
    替换为阿里源
    # 查看 brew.git 当前源
    $ cd "$(brew --repo)" && git remote -v
    origin    https://github.com/Homebrew/brew.git (fetch)
    origin    https://github.com/Homebrew/brew.git (push)
    
    # 查看 homebrew-core.git 当前源
    $ cd "$(brew --repo homebrew/core)" && git remote -v
    origin    https://github.com/Homebrew/homebrew-core.git (fetch)
    origin    https://github.com/Homebrew/homebrew-core.git (push)
    
    # 修改 brew.git 为阿里源
    $ git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
    
    # 修改 homebrew-core.git 为阿里源
    $ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
    
    # zsh 替换 brew bintray 镜像
    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
    $ source ~/.zshrc
    
    # bash 替换 brew bintray 镜像
    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
    $ source ~/.bash_profile
    
    # 刷新源
    $ brew update
    

    替换为清华源

    # 替换各个源
    $ git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
    $ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
    $ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
    
    # zsh 替换 brew bintray 镜像
    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
    $ source ~/.zshrc
    
    # bash 替换 brew bintray 镜像
    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
    $ source ~/.bash_profile
    
    # 刷新源
    $ brew update
    

    替换为中科大源

    # 替换各个源
    $ git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
    $ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
    $ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
    
    # zsh 替换 brew bintray 镜像
    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
    $ source ~/.zshrc
    
    # bash 替换 brew bintray 镜像
    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
    $ source ~/.bash_profile
    
    # 刷新源
    $ brew update
    

    重置为官方源

    # 重置 brew.git 为官方源
    $ git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
    
    # 重置 homebrew-core.git 为官方源
    $ git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
    
    # 重置 homebrew-cask.git 为官方源
    $ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask
    
    # zsh 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置
    $ vi ~/.zshrc
    # export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
    
    # bash 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置
    $ vi ~/.bash_profile
    # export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
    
    # 刷新源
    $ brew update
    

    单独配置镜像源

    如下:Homebrew 源使用帮助 — USTC Mirror Help 文档

    需要操作如下几步


    image.png

    相关文章

      网友评论

        本文标题:Mac全自动安装brew一键配置国内镜像源

        本文链接:https://www.haomeiwen.com/subject/asxiortx.html