Mac修改源并更新
Mac修改源并更新
替换中科大源
替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
替换Homebrew Bottles源: 参考:替换Homebrew Bottles源
对于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
替换清华源 清华源设置参考
替换现有上游
# brew 程序本身,Homebrew/Linuxbrew 相同
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 以下针对 mac OS 系统上的 Homebrew
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
git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
# 更换后测试工作是否正常
brew update
复原
(感谢Snowonion Lee提供说明)
# brew 程序本身,Homebrew/Linuxbrew 相同
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
# 以下针对 mac OS 系统上的 Homebrew
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
git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://github.com/Homebrew/homebrew-cask-fonts.git
git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://github.com/Homebrew/homebrew-cask-drivers.git
# 更换后测试工作是否正常
brew update
切换回官方源:
重置brew.git:
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
重置homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
注释掉bash配置文件里的有关Homebrew Bottles即可恢复官方源。 重启bash或让bash重读配置文件。
Brew更新
更新Homebrew自己
brew update
查看哪些安装包要更新
brew outdated
更新包
brew upgrade
brew upgrade $FORMULA #更新指定的包
清理旧版本
brew cleanup #清理所有包的旧版本
brew cleanup $FORMULA #清理指定包的旧版本
brew cleanup -n #查看可清理的旧版本包,不执行实际操作
锁定不想更新的包
brew pin $FORMULA #锁定某个包
brew unpin $FORMULA #取消锁定
对于一般的包使用上面的方式,还可以查看哪些包被pin
❯ brew list --pinned
zookeeper
但是对于cask中的包,必须使用另外一种配置
brew cu pin qq
brew cu unpin qq
查看
❯ brew cu list --pinned
Error: Using option --pinned for listing pinned apps is deprecated, please use "brew cu pinned" command.
Cask Current Latest
1/8 postman 10.1.2
2/8 shadowsocksx-ng-r 1.4.4-r8-resigning 1.4.4-r8-resigning
3/8 sensiblesidebuttons 1.0.6 1.0.6
4/8 snipaste 2.7.2-Beta
5/8 flux 41.4 42.1
6/8 alt-tab 6.47.0 6.49.0
7/8 keka 1.2.14 1.2.57
8/8 google-chrome 107.0.5304.62 107.0.5304.110
使用上述命令
查看安装包的相关信息
brew info $FORMULA #显示某个包的信息
brew info #显示安装了包数量,文件数量,和总占用空间
brew deps --installed --tree #查看已安装的包的依赖,树形显示
查看已安装的包
brew list
删除
brew rm $FORMULA #删除某个包
brew uninstall --force $FORMULA #删除所有版本
下面一句话搞定brew更新
brew update && brew upgrade && brew cleanup
brew upgrade $(brew list | awk '{print $1}' | xargs)
查看应用安装位置
比如查看pandoc
❯ brew list pandoc
/usr/local/Cellar/pandoc/2.12/bin/pandoc
/usr/local/Cellar/pandoc/2.12/etc/bash_completion.d/pandoc
/usr/local/Cellar/pandoc/2.12/share/man/man1/pandoc.1
Homebrew-Cask更新
brew cask list
brew cask outdated #列出需要更新的软件
brew call $FORMULA
brew cask uninstall $FORMULA
brew cask install --force <outdated-cask> #更新软件
brew cask upgrade $FORMULA #更新软件
下面一句话搞定cask更新
brew cask upgrade $(brew cask list | awk '{print $1}' | xargs)
总结
设置别名
alias brewu='brewu(){brew update && brew upgrade && brew cleanup && brew upgrade $(brew list | awk "{print \$1}" | xargs)};brewu'
alias brewc='brewc(){brew upgrade --cask && brew upgrade --cask $(brew list --cask | awk "{print \$1}" | xargs)};brewc'
alias brewa='brewa(){brewu && brewc };brewa'
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
2017-05-30 Java并发编程之CAS