mac big sur版本安装brew及替换国内镜像

1、下载脚本

cd ~
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh >> brew_install

如果无法访问,修改host,添加以下内容

199.232.68.133 raw.githubusercontent.com

修改brew_install源git仓库

#BREW_REPO = “https://github.com/Homebrew/brew”
BREW_REPO = “git://mirrors.ustc.edu.cn/brew.git”

执行命令进行安装

sh brew_install
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew
==> The following new directories will be created:
/opt/homebrew/bin
/opt/homebrew/etc
/opt/homebrew/include
/opt/homebrew/lib
/opt/homebrew/sbin
/opt/homebrew/share
/opt/homebrew/var
/opt/homebrew/opt
/opt/homebrew/share/zsh
/opt/homebrew/share/zsh/site-functions
/opt/homebrew/var/homebrew
/opt/homebrew/var/homebrew/linked
/opt/homebrew/Cellar
/opt/homebrew/Caskroom
/opt/homebrew/Frameworks

Press RETURN to continue or any other key to abort

2、解决安装core/cask失败

==> Tapping homebrew/core
Cloning into ‘/opt/homebrew/Library/Taps/homebrew/homebrew-core’…
fatal: unable to access ‘https://github.com/Homebrew/homebrew-core/’: LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60
Error: Failure while executing; git clone https://github.com/Homebrew/homebrew-core /opt/homebrew/Library/Taps/homebrew/homebrew-core exited with 128.
Error: Failure while executing; /opt/homebrew/bin/brew tap homebrew/core exited with 1.
Failed during: /opt/homebrew/bin/brew update --force

Control+C 中断安装

cd /opt/homebrew/Library/Taps
mkdir homebrew #如果存在此文件夹就跳过这一步
cd homebrew
git clone https://mirrors.ustc.edu.cn/homebrew-core.git
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git

完成安装

cd ~
sh brew_install
➜ ~ sh brew_install
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /usr/sbin/chown yuanjian:admin /opt/homebrew
==> Downloading and installing Homebrew…
HEAD is now at 4a90a5a5d Merge pull request #10199 from reitermarkus/check-https-content
Already up-to-date.
Warning: /opt/homebrew/bin is not in your PATH.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics data has been sent yet (or will be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations

==> Next steps:

  • Run brew help to get started
  • Further documentation:
    https://docs.brew.sh
    ➜ ~ brew --version

3、添加到path

brew --version
zsh: command not found: brew #如果可以显示出版本号则跳过此节
vi ~/.zshrc

敲击I键,添加以下内容后,ESC键,后输入 “:wq”保存

export PATH=$PATH:/opt/homebrew/bin

source ~/.zshrc
brew --version
Homebrew 2.7.1

4、替换为国内源

替换核心软件仓库

cd “$(brew --repo)”
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git

替换core源

cd “$(brew --repo)/Library/Taps/homebrew/homebrew-core”
git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git

替换cask源

cd “$(brew --repo)/Library/Taps/homebrew/homebrew-cask”
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

替换Bottles源

echo ‘export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles’ >> ~/.zshrc
source ~/.zshrc

5、检查

brew update

Already up-to-date.

Mac下使用国内镜像安装Homebrew,解决brewmac安装软件下载慢的问题,zip包内已经替换国内镜像文件, Mac OS 安装 brew 已经替换国内源,直接使用即可 1.把 brew_install 复制到 /users目录 2.安装 ruby ./brew_install ———————————————————————————————————————————— 替换bottles 镜像源(可选) 该镜像是 Homebrew 二进制预编译包的镜像。 临时替换 export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles 长期替换 echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile source ~/.bash_profile ———————————————————————————————————————————— 常用命令 brew的常用命令 安装软件: brew install git 卸载软件: brew uninstall git 搜索软件: brew search git 显示已经安装软件列表: brew list 查看软件信息: brew [info | home] [FORMULA...] 删除旧版本安装包缓存: brew cleanup gitbrew cleanup 查看那些已安装的程序需要更新: brew outdated 更新软件,把所有的Formula目录更新,并且会对本机已经安装并有更新的软件用*标明: brew update 更新某具体软件: brew upgrade git 锁定某个软件禁止更新: brew pin git 解除禁更锁定: brew unpin git 查看brew存放安装包的缓存地址: brew --cache 服务相关命令 显示安装的服务: brew services list 启动: brew services start mysql 停止: brew services stop mysql 重启: brew services restart mysql
### HomebrewmacOS 11.4 上的兼容性与安装建议 macOS 11.4(Big Sur)是 Apple 推出的一个较早期的系统版本,Homebrew 作为一个广泛使用的包管理器,对于该版本的系统具备良好的兼容性。Homebrew 的官方仓库通常会保持对最新几个 macOS 版本的支持,因此在 macOS 11.4 上安装最新版本的 Homebrew 是可行的,并且不会出现显著的兼容性问题[^1]。 Homebrew 的核心安装脚本会自动检测系统环境,并根据操作系统的版本适配相应的依赖库和工具链。因此,用户可以直接使用官方推荐的安装命令进行安装: ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 该命令会自动安装与当前系统兼容的 Homebrew 版本,包括对 macOS 11.4 的适配支持[^2]。安装完成后,可以通过以下命令验证 Homebrew 是否正常运行: ```bash brew doctor ``` 如果系统提示 `Your system is ready to brew.`,则表示 Homebrew 已正确安装并适配当前系统环境。 ### 替换 Homebrew 源以提升安装速度(可选) 由于 Homebrew 的默认源位于国外服务器,部分用户在使用过程中可能会遇到下载速度较慢的问题。为提升 Homebrew 的使用体验,可以将默认源替换国内镜像,例如清华大学的 Homebrew 镜像源: ```bash cd "$(brew --repo)" git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git ``` 完成源替换后,再次运行 `brew update`,应可显著提升仓库同步速度[^1]。 --- ### 注意事项 - 在 macOS 11.4 上安装 Homebrew 时,确保系统已安装 Xcode 命令行工具,可通过以下命令安装: ```bash xcode-select --install ``` - 如果用户曾手动删除 Homebrew 或其相关目录,建议先运行清理命令再重新安装: ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值