mac homebrow 安装与配置2021年12月13日

Homebrew 是什么

Homebrew是 mac的包管理器,仅需执行相应的命令,就能下载安装需要的软件包,可以省掉自己去下载、解压、拖拽(安装)等繁琐的步骤。

比如安装服务器 nginx,打开终端执行以下命令即可安装:

brew install nginx

如何安装?

方法二:使用brew镜像安装

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"

执行到最后提示安装成功,

然后执行brew -v,brew提示:command not found 解决方法

修改配置:

vim ~/.bash_profile

打开终端输入 brew提示:command not found 解决方法

输入命令:

sudo vim .bash_profile

然后输入以下代码:

export PATH=/usr/local/bin:$PATH

再使用以下命令使配置生效:

source .bash_profile

这样就可以使用brew命令了

 

 

Homebrew安装完为何需要配置

前面已经提到,Homebrew通常用来下载软件的,但它在安装软件时非常慢。为了提升安装速度,需要更改 Homebrew 的安装源,将其替换成国内镜像。

这里用的是由中科大负责托管维护的 Homebrew 镜像。其中,前两个为必须配置的项目,后两个可按需配置。

1.必备设置

  • 替换 brew.git:
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
  • 替换 homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

2.按需设置

  • 替换 homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
  • 替换homebrew-bottles:

首先要先区分你的mac用哪种终端工具,如果是 bash,则执行:

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

若是 zsh,则执行:

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

注:Homebrew 主要由四个部分组成: brew、homebrew-core 、homebrew-cask、homebrew-bottles,它们对应的功能如下:

组成功能
Homebrew 源代码仓库
homebrew-core Homebrew 核心源
homebrew-cask 提供macos应用和大型二进制文件的安装
homebrew-bottles 预编译二进制软件包

Homebrew 基本用法有哪些

复制代码
// 查询:
brew search 软件名

// 安装:
brew install 软件名

// 卸载:
brew uninstall 软件名

// 更新 Homebrew:
brew update 

// 查看 Homebrew 配置信息:
brew config 

// 查看包列表
brew list

// 查看包详情
brew info 软件名

// 查看brew版本
brew -v

// 查看帮助信息
brew -h
复制代码

注:使用官方脚本同样会遇到uninstall地址无法访问问题,可以替换为下面脚本:

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"

卸载Homebrew

复制代码
cd `brew --prefix`
rm -rf Cellar
brew prune
rm `git ls-files`
rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
rm -rf .git
rm -rf ~/Library/Caches/Homebrew



复制代码
 
 
参考:https://www.cnblogs.com/aaronthon/p/15601485.html
原文地址:https://www.cnblogs.com/shay/p/15683967.html