本机已安装软件
xxx1930@xxxdeMacBook-Pro ~ % brew list
==> Formulae
abseil libssh2 openssl@3 readline xz
ca-certificates lua pcre sqlite zsh-autosuggestions
iproute2mac mpdecimal protobuf trzsz zsh-completions
liblinear nmap python@3.11 trzsz-ssh
==> Casks
google-chrome mos popclip
常用命令
# Mac终端上Homebrew的常用命令:
brew update :更新Homebrew至最新版本
brew search :搜索需要的安装包
brew install :安装指定的安装包
brew uninstall :卸载指定的安装包
brew list :列出已安装的包名
brew upgrade :升级所有已安装的包
brew outdated :查看所有可更新的包
brew doctor :检测Homebrew环境是否健康
brew info :查看包信息
brew cleanup :清理旧版本的包及缓存
# 更多的可能用到的命令:
brew tap :添加或删除外部tap源
brew search --desc :搜索描述中包含特定关键词的包
brew search --cask :搜索cask包
brew cask install :安装指定的cask包
brew cask uninstall :卸载指定的cask包
brew services :管理Homebrew服务
brew link :连接包的二进制文件到PATH中
brew unlink :取消连接包的二进制文件
brew style :检查Homebrew包的代码风格
brew edit :编辑指定的Homebrew包信息和代码
参考网址
Homebrew国内源--- 安装
MacOS必备神器Homebrew 操作命令
超燃!高效 MacBook 工作环境配置,超实用!
# homebrew-core, homebrew-cash, homebrew-services 的安装位置
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-cask'
Homebrew官方的源一般下载包之类的会很慢,所以通常我们都是用国内的镜像源来代替,这样会提高我们的效率。Homebrew主要有四个部分组成: brew、homebrew-core 、homebrew-bottles、homebrew-cask。
# 名称 说明
brew Homebrew 源代码仓库
homebrew-core Homebrew 核心软件仓库
homebrew-bottles Homebrew 预编译二进制软件包
homebrew-cask MacOS 客户端应用
# Homebrew 国内镜像源目前主要有中科大镜像、阿里镜像、清华镜像。
# 首先查看自己本地的镜像源地址是什么,在命令行输入以下命令可以查询:
# 查看 brew.git 当前源
cd "$(brew --repo)" && git remote -v
# 查看 homebrew-core.git 当前源
cd "$(brew --repo homebrew/core)" && git remote -v
Homebrew更换国内镜像源(中科大、阿里、清华)
安装示例
suosuo1930@suosuodeMacBook-Pro ~ % /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
开始执行Homebrew自动安装程序
[cunkai.wang@foxmail.com]
['2023-08-26 14:22:02']['13.4']
https://zhuanlan.zhihu.com/p/111014448
请选择一个下载brew本体的序号,例如中科大,输入1回车。
源有时候不稳定,如果git克隆报错重新运行脚本选择源。
1、中科大下载源
2、清华大学下载源
3、北京外国语大学下载源
4、腾讯下载源
5、阿里巴巴下载源
6、跳过下载brew去配置下载源
请输入序号: 5
你选择了阿里巴巴brew本体下载源
!!!此脚本将要删除之前的brew(包括它下载的软件),请自行备份。
->是否现在开始执行脚本(N/Y) y
--> 脚本开始执行
Mac os设置开机密码方法:
(设置开机密码:在左上角苹果图标->系统偏好设置->用户与群组->更改密码)
(如果提示This incident will be reported. 在用户与群组中查看是否管理员)
==> 通过命令删除之前的brew、创建一个新的Homebrew文件夹
请输入开机密码,输入过程不显示,输入完后回车
Password:
开始执行
---备份要删除的/opt/homebrew到系统桌面....
---/opt/homebrew 备份完成
-> 创建文件夹 /opt/homebrew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /opt/homebrew
此步骤成功
运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /opt/homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown suosuo1930 /opt/homebrew
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /opt/homebrew
git version 2.33.0
下载速度觉得慢可以ctrl+c或control+c重新运行脚本选择下载源
==> 从 https://mirrors.aliyun.com/homebrew/brew.git 克隆Homebrew基本文件
未发现Git代理(属于正常状态)
Cloning into '/opt/homebrew'...
Fetching objects: 246231, done.
Checking connectivity: 246231, done.
此步骤成功
--创建Brew所需要的目录
运行代码 ==> The following existing directories will be made group writable:
/opt/homebrew/bin
/opt/homebrew/bin/brew
运行代码 ==> The following existing directories will have their owner set to suosuo1930:
/opt/homebrew/bin
/opt/homebrew/bin/brew
运行代码 ==> The following new directories will be created:
/opt/homebrew/etc
/opt/homebrew/include
/opt/homebrew/lib
/opt/homebrew/sbin
/opt/homebrew/share
/opt/homebrew/var
/opt/homebrew/opt
/opt/homebrew/share/zsh
/opt/homebrew/share/zsh/site-functions
/opt/homebrew/var/homebrew
/opt/homebrew/var/homebrew/linked
/opt/homebrew/Cellar
/opt/homebrew/Caskroom
/opt/homebrew/Frameworks
运行代码 ==> /usr/bin/sudo /bin/chmod u+rwx /opt/homebrew/bin /opt/homebrew/bin/brew
运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /opt/homebrew/bin /opt/homebrew/bin/brew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown suosuo1930 /opt/homebrew/bin /opt/homebrew/bin/brew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
运行代码 ==> /usr/bin/sudo /bin/chmod ug=rwx /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
运行代码 ==> /usr/bin/sudo /bin/chmod go-w /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions
运行代码 ==> /usr/bin/sudo /usr/sbin/chown suosuo1930 /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R suosuo1930:admin /opt/homebrew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /Users/suosuo1930/Library/Caches/Homebrew
运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /Users/suosuo1930/Library/Caches/Homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R suosuo1930 /Users/suosuo1930/Library/Caches/Homebrew
--依赖目录脚本运行完成
==> 创建brew的替身
brew下载完成。
如果需要Core、Cask、services的话,输入Y继续克隆
不需要的回车跳过:y
==> 从 https://mirrors.aliyun.com/homebrew/homebrew-core.git 克隆Homebrew Core
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-core'...
Fetching objects: 1590266, done.
Checking connectivity: 1590266, done.
此步骤成功
==> 从 https://mirrors.aliyun.com/homebrew/homebrew-cask.git 克隆Homebrew Cask 图形化软件
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Password:
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-cask'...
Fetching objects: 776219, done.
Checking connectivity: 776219, done.
此步骤成功
==> 从 https://gitee.com/cunkai/homebrew-services.git 克隆Homebrew services 管理服务的启停
Password:
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 2472, done.
remote: Counting objects: 100% (1331/1331), done.
remote: Compressing objects: 100% (655/655), done.
remote: Total 2472 (delta 702), reused 1277 (delta 650), pack-reused 1141
Receiving objects: 100% (2472/2472), 657.96 KiB | 928.00 KiB/s, done.
Resolving deltas: 100% (1186/1186), done.
此步骤成功
All user-space services OK, nothing cleaned...
==> 配置国内镜像源HOMEBREW BOTTLE
此处如果显示Password表示需要再次输入开机密码,输入完后回车
sed: /Users/suosuo1930/.zprofile: No such file or directory
有些电脑xcode和git混乱,再运行一次,此处如果有error正常。
xcode-select: note: install requested for command line developer tools
Homebrew已经安装成功,接下来配置国内源。
请选择今后brew install的时候访问那个国内镜像,例如阿里巴巴,输入5回车。
1、中科大国内源
2、清华大学国内源
3、北京外国语大学国内源
4、腾讯国内源
5、阿里巴巴国内源
请输入序号: 5
你选择了阿里巴巴国内源
环境变量写入->/Users/suosuo1930/.zprofile
此步骤成功
运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /opt/homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown suosuo1930 /opt/homebrew
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /opt/homebrew
==> 安装完成,brew版本
Homebrew >=2.5.0 (shallow or no git repository)
xcode-select: note: No developer tools were found, requesting install.
If developer tools are located at a non-default location on disk, use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, and cancel the installation dialog.
See `man xcode-select` for more details.
Homebrew/homebrew-core (no Git repository)
xcode-select: note: No developer tools were found, requesting install.
If developer tools are located at a non-default location on disk, use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, and cancel the installation dialog.
See `man xcode-select` for more details.
Homebrew/homebrew-cask (no Git repository)
Homebrew前期配置成功
电脑系统版本:13.4
==> brew update-reset
HOMEBREW_VERSION: >=2.5.0 (shallow or no git repository)
ORIGIN: (none)
HEAD: (none)
Last commit: never
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: (none)
Core tap last commit: never
Core tap branch: (none)
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_API_DOMAIN: https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api
HOMEBREW_BOTTLE_DOMAIN: https://mirrors.aliyun.com/homebrew/homebrew-bottles
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 10
HOMEBREW_PIP_INDEX_URL: https://pypi.tuna.tsinghua.edu.cn/simple
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: 10-core 64-bit arm_blizzard_avalanche
Clang: N/A
Git: N/A
Curl: 7.88.1 => /usr/bin/curl
macOS: 13.4-arm64
CLT: N/A
Xcode: N/A
Rosetta 2: false
失败5 终端输入 /opt/homebrew/bin/brew -v 没有反应表示失败
右键下面地址查看常见错误解决办法
https://gitee.com/cunkai/HomebrewCN/blob/master/error.md
或者别的安装方法:https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
如果没有解决,把全部运行过程截图发到 cunkai.wang@foxmail.com
suosuo1930@suosuodeMacBook-Pro ~ %
suosuo1930@suosuodeMacBook-Pro ~ %
suosuo1930@suosuodeMacBook-Pro ~ %
suosuo1930@suosuodeMacBook-Pro ~ %
suosuo1930@suosuodeMacBook-Pro ~ % brew -v
zsh: command not found: brew
suosuo1930@suosuodeMacBook-Pro ~ %
Desktop/ Homebrew/ Music/ Virtual\ Machines.localized/ tmp/
Documents/ Library/ Pictures/ VirtualBox\ VMs/ virtualBox_vms/
Downloads/ Movies/ Public/ pycharm_Pro/ vmware_fusion13.rtf
# 安装 xcrun
suosuo1930@suosuodeMacBook-Pro ~ % git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cor
suosuo1930@suosuodeMacBook-Pro ~ % brew -v
Homebrew 4.1.6-16-g3c8b494-dirty
fatal: detected dubious ownership in repository at '/opt/homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/opt/homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)
suosuo1930@suosuodeMacBook-Pro ~ % git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
suosuo1930@suosuodeMacBook-Pro ~ % git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
suosuo1930@suosuodeMacBook-Pro ~ % brew -v
Homebrew 4.1.6-16-g3c8b494-dirty
Homebrew/homebrew-core (git revision 40cc9ca9a1d; last commit 2023-08-25)
Homebrew/homebrew-cask (git revision 4c17b218f01; last commit 2023-08-25)
suosuo1930@suosuodeMacBook-Pro ~ %
suosuo1930@suosuodeMacBook-Pro ~ % ip a
zsh: command not found: ip
suosuo1930@suosuodeMacBook-Pro ~ %
suosuo1930@suosuodeMacBook-Pro ~ %
suosuo1930@suosuodeMacBook-Pro ~ %