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

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

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

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

相关推荐
梦魇梦狸º7 小时前
mac 配置 python 环境变量
chrome·python·macos
丁总学Java12 小时前
macOS如何进入 Application Support 目录(cd: string not in pwd: Application)
macos
qdprobot12 小时前
Mixly米思齐1.0 2.0 3.0 软件windows版本MAC苹果电脑系统安装使用常见问题与解决
windows·macos
麦克Mapp12 小时前
不用安装双系统,如何在mac上玩windows游戏呢?
macos
符小易12 小时前
Mac苹果电脑 怎么用word文档和Excel表格?
macos·word·excel
梦魇梦狸º16 小时前
node安装与管理
macos·node.js
缘友一世1 天前
macOS查看当前项目的 tree 结构
macos
梦魇梦狸º1 天前
mac 安装 python2
python·macos
篮l球场2 天前
mac m1下载maven安装并配置环境变量
macos
YAIMZA2 天前
mac配置 iTerm2 使用lrzsz与服务器传输文件
服务器·macos·lrzsz