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

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

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

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

相关推荐
colorknight3 小时前
1.2.3 HuggingFists安装说明-MacOS安装
人工智能·低代码·macos·huggingface·数据科学·ai agent
GEEKVIP10 小时前
如何修复变砖的手机并恢复丢失的数据
macos·ios·智能手机·word·手机·笔记本电脑·iphone
kuai-11 小时前
MacOS配置python环境
开发语言·python·macos
一丝晨光11 小时前
继承、Lambda、Objective-C和Swift
开发语言·macos·ios·objective-c·swift·继承·lambda
心存留恋就不会幸福17 小时前
Mac屏蔽系统更新,取出红点标记&&如果解锁hosts文件
macos
GEEKVIP1 天前
iPhone/iPad技巧:如何解锁锁定的 iPhone 或 iPad
windows·macos·ios·智能手机·笔记本电脑·iphone·ipad
超爱找事1 天前
iMazing只能苹果电脑吗 Win和Mac上的iMazing功能有区别吗
windows·macos·电脑·数据备份·苹果·imazing
代吗喽1 天前
Macos终端常用的命令行指令总结
macos·命令行
无名草鸟1 天前
macOS终端配置自动补全功能
macos
Nyingchi-X1 天前
Navicat Premium 12 for Mac中文永久版
mysql·macos