秀杰空间

秀杰笔记
做些有意义的事情
  1. 首页
  2. 开发环境
  3. 正文

Mac安装Brew(Homebrew)国内镜像源加速

2023年2月13日 9175点热度 0人点赞 0条评论

brew 介绍


brew 全称叫Homebrew,是Mac系统上的软件包管理工具。这里的软件并不是指从AppStore或从网上下载的dmg文件,而是下载源码解压然后 ./configure && make install ,同时会包含相关依存库。并自动配置好各种环境变量,而且非常易于卸载。 这个对程序员来说简直是福音,简单的指令,就能快速安装和升级本地的各种开发环境。作用类似 apt-get 或 yum。

brew 官方网站 : https://brew.sh/

Homebrew 主要有四个部分组成: brew、homebrew-core 、homebrew-bottles、homebrew-cask。

名称 说明
brew Homebrew 源代码仓库
homebrew-core Homebrew 核心软件仓库
homebrew-bottles Homebrew 预编译二进制软件包.比如curl、wget、python等。
homebrew-cask 提供 macOS 应用和大型二进制文件。比如chrome、firefox、iterm2等。

brew 安装

官方首次安装指令(国内未加速),终端下运行:

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

中科大首次安装指令(国内加速),终端下运行:

export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"

/bin/bash -c "$(curl -fsSL https://mirrors.ustc.edu.cn/misc/brew-install.sh)"

已安装brew,使用中科大国内镜像加速配置如下:

# 环境变量 HOMEBREW_BREW_GIT_REMOTE 加入 shell 的 profile 设置中。
# 对于 bash 用户
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"' >> ~/.bash_profile
brew update

# 对于 zsh 用户
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"' >> ~/.zshrc
brew update

常用一些国内镜像源(国内加速)

镜像源名称 镜像使用帮助网址
中科大镜像站 http://mirrors.ustc.edu.cn/help/brew.git.html
清华大学开源软件镜像站 https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
阿里云镜像站 https://developer.aliyun.com/mirror/homebrew/
腾讯云镜像站 https://mirrors.cloud.tencent.com/help/homebrew.html

brew 常用命令

命令 说明 示例
brew install [包名] 安装包 brew install wget
brew upgrade [包名] 更新指定包 brew upgrade protobuf
brew upgrade 更新全部包 brew upgrade
brew uninstall [包名] 卸载指定包 brew uninstall protobuf
brew info [包名] 查看包信息 brew info protobuf
brew search [包名] 模糊搜索可用包 brew search python
brew list 查看已安装列表 brew list
brew cleanup 清理旧版本和下载的缓存 brew cleanup
brew update 更新brew软件自身 brew update
brew -v 查看版本 brew -v
brew outdated 查询可更新的包 brew outdated
brew help 查看帮助信息 brew help
brew deps [包名] 列出软件包的依赖关系 brew deps wget

常见错误

错误: Error: undefined method `launchd_service_path

Error: undefined method `launchd_service_path

解决:

brew update -v

错误:brew complains about absence of “Command Line Tools”

解决:

xcode-select --install
标签: mac
最后更新:2023年2月13日

秀杰

做些有意义的事情

点赞
< 上一篇

文章评论

您需要 登录 之后才可以评论

COPYRIGHT © 2023 个人笔记. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

京ICP备11019155号-2