个人博客 个人博客
首页
  • 前端
  • 后端
  • Git
  • Docker
  • 网络
  • 操作系统
工具
阅读
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

董先亮

前端react开发
首页
  • 前端
  • 后端
  • Git
  • Docker
  • 网络
  • 操作系统
工具
阅读
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • homebrew
    • 1. 介绍
    • 2. 安装
      • 2.1 执行安装脚本
      • 2.2 验证安装成功
      • 2.3 更换下载源
      • 2.3.1 更换brew.git
      • 2.3.2 更换homebrew-core.git
      • 2.3.3 更换homebrew-cask.git
      • 2.3.4 更换homebrew-bottles
      • 2.3.5 更新软件包
      • 2.4 恢复默认源
    • 3. 意外处理
    • 4. 常用命令
      • 4.1 安装软件
      • 4.2 更新软件
      • 4.3 卸载软件
      • 4.4 服务相关
      • 4.5 其他常用命令
    • 5. 卸载Homebrew
    • 6. 参考
  • yarn
  • npm
  • eslint
  • prettier
  • lint-staged
  • pretty-quick
  • husky
  • commitlint
  • pnpm
  • npx
  • vite
  • git
  • iTerm配置
  • Mac常见问题
  • 工具
NeverStop1024
2022-08-29
目录

homebrew

# 1. 介绍

Homebrew (opens new window)是一款包管理工具,目前支持macOS和Linux系统。主要有四个部分组成:brew、homebrew-core 、homebrew-cask、homebrew-bottles。 image.png

# 2. 安装

# 2.1 执行安装脚本

执行/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)",镜像选阿里巴巴,傻瓜式安装,30分钟左右,安装完成。

# 2.2 验证安装成功

执行brew --version 验证是否安装成功。

# 2.3 更换下载源

# 2.3.1 更换brew.git

git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git # 中科大
或
git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git # 阿里巴巴
或
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git # 清华大学
1
2
3
4
5

# 2.3.2 更换homebrew-core.git

git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git # 中科大
或
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git # 阿里巴巴
或
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git # 清华大学
1
2
3
4
5

# 2.3.3 更换homebrew-cask.git

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git # 中科大
或
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git # 阿里巴巴
或
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git # 清华大学
1
2
3
4
5

# 2.3.4 更换homebrew-bottles

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile # 阿里云
或
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile # 中科大
或
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile # 清华大学

source ~/.bash_profile
1
2
3
4
5
6
7

如果终端使用的是zsh,就写入zsh的配置文件中。

# 2.3.5 更新软件包

执行brew update,如果可以更新成功,更换的源可用。

# 2.4 恢复默认源

某些情况下,可能我们使用的国内源挂掉了,就需要恢复默认源。

1. git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
2. git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
3. git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
4. 删除环境变量 HOMEBREW_BOTTLE_DOMAIN
5. source ~/.bash_profile
6. brew update
1
2
3
4
5
6

# 3. 意外处理

  1. 先执行brew doctor查看问题,按照指示对问题进行修复
  2. 执行brew update-reset 将homebrew还原到稳定版
  3. 执行brew update 更新软件包

# 4. 常用命令

# 4.1 安装软件

  • brew install node 默认安装最新版
  • brew install node@14.16.8 安装指定版本
  • brew switch node 16.0.0 切换版本

# 4.2 更新软件

  • brew upgrade name 更新安装过的软件(如果不加软件名,就更新所有可以更新的软件)

# 4.3 卸载软件

  • brew uninstall node 卸载node

# 4.4 服务相关

  • brew services list 获取services列表
  • brew services start/stop/restart serverName
    • brew services start mysql 启动mysql服务
    • brew services restart mysql 重启mysql服务
    • brew services stop mysql 停止mysql服务

# 4.5 其他常用命令

  • brew config 查看brew配置
  • brew info node 查看node安装信息
  • brew list 查看已安装软件
  • brew list --versions 查看已安装软件版本号
  • brew search node 搜索可用node相关软件
  • brew update brew自身更新
  • brew cleanup 清除下载的缓存
  • brew doctor 诊断brew,并给出修复命令

# 5. 卸载Homebrew

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

# 6. 参考

  1. Homebrew国内如何自动安装(国内地址)(Mac & Linux) (opens new window)
编辑 (opens new window)
#homebrew
上次更新: 2023/02/19
yarn

yarn→

最近更新
01
mock使用
07-12
02
websocket即时通讯
07-12
03
前端面试题
07-09
更多文章>
Theme by Vdoing | Copyright © 2022-2023 NeverStop1024 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式