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

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


1、简介

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

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


2、安装

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


(1)安装包安装

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

这里比较简单,不多介绍


(2)命令行安装

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

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

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

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

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


报错一

Failed to connect to raw.githubusercontent.com port 443: Connection refused

解决一

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

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

bash install.sh

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

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

报错二

Failed during: /usr/bin/git fetch --force origin

解决二

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

git config --global user.name  your_name
git config --global user.email your_email

注意,需要把 your_nameyour_email 替换掉


报错三

Failed during: /opt/homebrew/bin/brew update --force --quiet

解决三

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

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>

(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"

完成之后,即可使用

brew help

3、使用

# 下载指定软件包
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


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

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

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

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-07 06:10:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-07 06:10:03       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-07 06:10:03       82 阅读
  4. Python语言-面向对象

    2024-04-07 06:10:03       91 阅读

热门阅读

  1. 设计模式:策略模式示例

    2024-04-07 06:10:03       29 阅读
  2. 计算机网络路由的配置

    2024-04-07 06:10:03       34 阅读
  3. C语言预处理基础知识笔记

    2024-04-07 06:10:03       34 阅读
  4. YOLOv5实战记录03 数据集构建

    2024-04-07 06:10:03       30 阅读
  5. go | gin多服务 | goroutine | ReadTimeout&WriteTimeout

    2024-04-07 06:10:03       38 阅读
  6. ffmpeg 从现有视频中截取一段

    2024-04-07 06:10:03       37 阅读
  7. 如何从vue项目界面上看出来node.js版本

    2024-04-07 06:10:03       33 阅读
  8. cycle GAN

    2024-04-07 06:10:03       36 阅读