Homebrew介绍和使用


前言

Homebrew 是一款包管理工具,目前支持 macOS 和 Linux 系统。主要有四个部分组成: brewhomebrew-corehomebrew-caskhomebrew-bottles

名称说明
brewHomebrew 源代码仓库
homebrew-coreHomebrew 核心源
homebrew-cask提供 macOS 应用和大型二进制文件的安装
homebrew-bottles预编译二进制软件包

一、Homebrew是什么?

Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷。

比如说,我们想要下载JDK,想要下载MySQL,需要去到各个官网进行下载
而 HomeBrew 类似于 Maven 一样,Maven管理着我们的依赖,而 Homebrew 里面存着我们开发需要用到的大部分套件,Homebrew —— OS X 不可或缺的套件管理器。

二、HomeBrew安装

/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"

默认使用中科大源

最后看到 Installation successful! 就说明安装成功了。
还需要更换Homebrew Bottle源,这个只要在shell配置文件里加上(或更改)一个变量即可。
zsh就是编辑~/.zshrc文件, bash就是~/.bash_profile,一定要注意自己的SHELL的版本,否则配置了不生效

# 安装完成后设置
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zshrc
source ~/.zshrc

查看Homebrew的版本

zhouxucong ~ % brew --version
Homebrew 3.2.0
Homebrew/homebrew-core (git revision be99503861; last commit 2021-07-01)

三、安装Git

因为后续如果需要换源,需要用到 Git 相关命令,顺便体验下使用 HomeBrew 安装 Git

brew install git

直接使用这个命令,等待安装完成,完成后使用 git --version 查看安装版本

zhouxucong ~ % git --version
git version 2.14.1

四、HomeBrew换源

根据shell的版本,zsh就是编辑~/.zshrc文件, bash就是~/.bash_profile,一定要注意自己的SHELL的版本,否则配置了不生效

中科大(建议使用)

# 脚本
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
brew update

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

阿里云

# 替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 应用生效
brew update
# 替换homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

清华

# 脚本
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
brew update

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles' >> ~/.zshrc
source ~/.zshrc

腾讯

# 脚本
git -C "$(brew --repo)" remote set-url origin https://mirrors.cloud.tencent.com/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.cloud.tencent.com/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.cloud.tencent.com/homebrew/homebrew-cask.git
brew update

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

初始默认镜像(国外源)

# 脚本
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update

homebrew-bottles配置只能手动删除,将 ~/.zshrc 文件中的 HOMEBREW_BOTTLE_DOMAIN=https://mirrors.xxx.com内容删除,并执行 source ~/.zshrc

可以通过 brew config 查看当前正在使用

zhouxucong ~ % brew config
HOMEBREW_VERSION: 3.2.0
ORIGIN: https://mirrors.ustc.edu.cn/brew.git
HEAD: 09f7bc27a99469cf947431df4754737dfbadb31d
Last commit: 2 months ago
Core tap ORIGIN: https://mirrors.ustc.edu.cn/homebrew-core.git
Core tap HEAD: be9950386188986fb14fea4fbabe5378df0a1013
Core tap last commit: 9 weeks ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_BOTTLE_DOMAIN: https://mirrors.ustc.edu.cn/homebrew-bottles/bottles
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 12
Homebrew Ruby: 2.6.3 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3_2/bin/ruby
CPU: dodeca-core 64-bit kabylake
Clang: 12.0.0 build 1200
Git: 2.14.1 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 10.15.7-x86_64
CLT: 12.4.0.0.1.1610135815
Xcode: N/A

五、HomeBrew基本使用命令

查看brew的帮助

brew –help

搜索软件

brew search [软件名]

安装软件

brew install [软件名]

卸载软件

brew uninstall [软件名]

显示已经安装软件列表

brew list

更新某具体软件

brew upgrade [软件名]

暂时了解这么多足够了

六、HomeBrew卸载

/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall.sh)"

然后删掉 HOMEBREW_BOTTLE_DOMAIN 环境变量,将你终端文件 ~/.bash_profile或者 ~/.zshrc

HOMEBREW_BOTTLE_DOMAIN 删除

source ~/.bash_profile
或者
source ~/.zshrc
  • 13
    点赞
  • 101
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值