效率系列(十) macOS软件管理工具

大家好,我是半虹,这篇文章来讲 macOS 上的软件管理工具 Homebrew


1、简介

Homebrew 是 macOS 上的包管理器,用户可以通过简单的命令行工具安装和管理软件包

Homebrew 在安装软件时能自动处理依赖问题,简化软件包的安装流程,非常推荐使用嘞

2、安装

Homebrew 提供两种安装方式,一是通过安装包安装,二是通过命令行安装

(1)安装包安装

根据官网说明,只需进入发布页面下载文件 Homebrew-X.Y.Z.pkg,然后双击进行安装即可

这里比较简单,不多介绍

(2)命令行安装

按照官网说明,也是一条命令即可完成安装

这条命令是说,先从指定地址下载安装脚本,再用 bash 执行脚本

shell 复制代码
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

看起来很简单,但在执行过程会有一些报错

下面介绍一下自己遇到的报错以及解决方案,大家也可以适当参考

报错一

shell 复制代码
Failed to connect to raw.githubusercontent.com port 443: Connection refused

解决一

这里的报错是说,终端无法连接到 raw.githubusercontent.com

如果浏览器是可以访问的,那么,可以手动下载上述文件,然后本地执行以下命令:

shell 复制代码
bash install.sh

如果浏览器也无法访问时,那么,可以从清华源下载脚本,然后进行安装

shell 复制代码
git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
bash brew-install/install.sh

报错二

shell 复制代码
Failed during: /usr/bin/git fetch --force origin

解决二

执行以下命令后,再重新执行 bash install.sh

shell 复制代码
git config --global user.name  your_name
git config --global user.email your_email

注意,需要把 your_nameyour_email 替换掉

报错三

shell 复制代码
Failed during: /opt/homebrew/bin/brew update --force --quiet

解决三

执行以下命令后,再重新执行 bash install.sh

shell 复制代码
export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"

这里,更具体的说明可以参考 官方文档

完整的安装输出如下:

复制代码
==> Checking for `sudo` access (which may request your password)...
Password:

==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew

==> HOMEBREW_BREW_GIT_REMOTE is set to a non-default URL:
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git will be used as the Homebrew/brew Git remote.
==> HOMEBREW_CORE_GIT_REMOTE is set to a non-default URL:
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git will be used as the Homebrew/homebrew-core Git remote.

Press RETURN/ENTER to continue or any other key to abort:

==> /usr/bin/sudo /usr/sbin/chown -R <username>:admin /opt/homebrew
==> Downloading and installing Homebrew...
Reset branch 'stable'
HOMEBREW_BREW_GIT_REMOTE set: using https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git as the Homebrew/brew Git remote.
==> Updating Homebrew...
Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/<username>/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run these commands in your terminal to add the non-default Git remotes for Homebrew/brew and Homebrew/homebrew-core:
    echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/<username>/.zprofile
    echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> /Users/<username>/.zprofile
    echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> /Users/<username>/.zprofile
    export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
    export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

可以看到,这里有个下一步的提示

按照提示,可以进行环境变量配置,如果直接复制下面的,则需要替换 <username>

shell 复制代码
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/<username>/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/<username>/.zprofile
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> /Users/<username>/.zprofile
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> /Users/<username>/.zprofile
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"

完成之后,即可使用

shell 复制代码
brew help

3、使用

shell 复制代码
# 下载指定软件包
brew install <package>
# 卸载指定软件包
brew uninstall <package>
# 升级指定软件包,若不指定 <package>,则为全部
brew upgrade <package>

# 模糊搜索未安装软件包
brew search <text|regex>
# 查看指定已安装软件包
brew info <package>
# 查看所有已安装软件包
brew list

# 更新 brew 以及软件包信息
brew update
# 清除 brew 缓存
brew cleanup

好啦,本文到此结束,感谢您的阅读!

如果你觉得这篇文章有需要修改完善的地方,欢迎在评论区留下你宝贵的意见或者建议

如果你觉得这篇文章还不错的话,欢迎点赞、收藏、关注,你的支持是对我最大的鼓励 (/ω\)

相关推荐
KevinShi_BJ20 小时前
MacOS 上安装 Docker 和启动 LangBot
macos
ricky_fan1 天前
(25年12月)claude code报错:might not be available in your country
macos·bash
james bid1 天前
MacBook Pro 2015 上 XUbuntu 24.04 启用 eGPU (GeForce GTX 1080 Ti) 和核显黑屏问题解决
linux·ubuntu·macos·cuda·egpu
私人珍藏库1 天前
[Mac] Mac风扇控制软件 iFan V1.1.1
macos
腾讯云qcloud07551 天前
腾讯位置商业授权iOS 轨迹SDK
macos·ios·cocoa
新手村领路人1 天前
MacOS Tahoe26.1自制定时休眠app
macos
2501_916007471 天前
没有 Mac,如何在 Windows 上架 iOS 应用?一套可落地的工程方案
android·macos·ios·小程序·uni-app·iphone·webview
乐之者v2 天前
mac操作快捷键命令
macos
一步徐龙的浪2 天前
Scholaread Mac版更新后无法用手机验证码登录
macos·scholaread·靠岸学术
ElenaYu2 天前
在 macOS 上安装 iOS Simulator(iPhone 模拟器)
macos·ios·iphone