CrazyAirhead

疯狂的傻瓜,傻瓜也疯狂——傻方能执著,疯狂才专注!

0%

Homebrew安装与更换源

Homebrew是什么

Homebrew是一款Mac OS平台下的软件包管理工具,通过一条指令,就可以实现包管理,包括安装、卸载、更新、查看、搜索等功能,而不用关心各种依赖,简单方便。

安装

要求

  • A 64-bit Intel CPU or Apple Silicon CPU 1
  • macOS Mojave (10.14) (或以上版本) 2
  • Xcode命令行工具: xcode-select --install, developer.apple.com/downloads or Xcode 3
  • 支持shell (比如bash或者 zsh) 4

安装

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

对于国内情况,可以加速Homebrew的安装

1
2
3
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/brew.git"  # put your Git mirror of Homebrew/brew here
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/homebrew-core.git" # put your Git mirror of Homebrew/homebrew-core here
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

卸载

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

更换源

更换源之前可以先查看源,Homebrew主要的有四部分组成:

  • brew Homebrew源代码仓库
  • homebrew-core Homebrew核心软件仓库
  • homebrew-bottles Homebrew预编译软件
  • homebrew-cask Macos客户端应用

查看命令

1
2
3
4
5
cd "$(brew --repo)" && git remote -v
cd "$(brew --repo homebrew/core)" && git remote -v



更换命令

1
2
3
4
5
6
7
8
9
10
cd "$(brew --repo)" && git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" && git remote set-url origin http://mirrors.aliyun.com/homebrew/homebrew-cask.git

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc


如果是10.15之前的版本,主要将~/.zshrc替换成~/.bash_profile

基础命令

  • 安装包

    1
    brew install <packageName>
  • 卸载包

    1
    brew uninstall <packageName>
  • 查询可用包

    1
    brew search <packageName>
  • 更新包

    1
    brew upgrade <packageName>
  • 查看已安装包列表

    1
    brew list
  • 查看包信息

    1
    brew info <packageName>
  • 更新Homebrew

    1
    brew update
  • 查看Homebrew版本

    1
    brew -v
  • Homebrew帮助信息

    1
    brew -h

欢迎关注我的其它发布渠道