效率系列(十) 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_name 和 your_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

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

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

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

相关推荐
七牛云行业应用14 小时前
DeepSeek Harness(dsh)安装完整指南:Windows、macOS、Linux 三平台 + 桌面端与 Web 端全覆盖
linux·windows·macos·ai·ai编程
全栈探索者18 小时前
一枚 162MB 的挂件,改写一只猫的画风:LoRA 实战——风格定制与人脸保持
人工智能·macos·lora·aigc·stablediffusion·comfyui
福大大架构师每日一题20 小时前
ollama v0.40.11发布:macOS原生语音生成上线,d3决策模型正式加入
macos·策略模式
小天源1 天前
智叟云集系统:便携部署、MAC 授权与交付排障
macos
Joy T1 天前
voice-dump-to-todo:把混乱的语音整理成可执行待办,一个实用的 Agent Skill
ide·macos·语音识别·xcode·任务管理·自研skill
JPower_mr.g2 天前
SmartCall v1.0.9 发布:智能体知识库上线,让 AI 客服先查资料再回答
java·ide·人工智能·macos·架构·开源·xcode
轻口味2 天前
启元无真机二开实战:先在Mac上养一台Q1——官方URDF到MuJoCo数字孪生的完整链
macos·具身智能·mujoco·启元机器人
2601_967979122 天前
AccessControl 5.4 macOS Python 3.9 版本安装包
python·macos·security·accesscontrol·permissions
EVE จุ๊บ3 天前
Mac安装Playwright
macos
全栈探索者3 天前
出图模型怎么选?同一只猫的四场实测:Z-Image、Qwen-Image 2.1、SD1.5 三维对决
人工智能·macos·aigc·stablediffusion·comfyui