【Homebrew】Homebrew 介绍与安装

tech2025-12-09  3

 

目录

一. 介绍

1.1 啥是 Homebrew 呢?

1.2 Homebrew 能干啥 ?

1.3 Homebrew 简单命令

二. 安装

2.1 WSL 安装

2.2 切换源

2.3 配置环境变量

2.4 恢复源(可选)

三. 参考


 

一. 介绍

1.1 啥是 Homebrew 呢?

macOS(或 Linux)缺失的软件包的管理器

 

1.2 Homebrew 能干啥 ?

我简单收集一下官方的描述,整理如下:

使用 Homebrew 安装 Apple(或您的 Linux 系统)没有预装但 你需要的东西。Homebrew 会将软件包安装到独立目录,并将其文件软链接至 /usr/local 。Homebrew 不会将文件安装到它本身目录之外,所以您可将 Homebrew 安装到任意位置。轻松创建你自己的 Homebrew 包。完全基于 Git 和 Ruby,所以自由修改的同时你仍可以轻松撤销你的变更或与上游更新合并。Homebrew 的配方都是简单的 Ruby 脚本;Homebrew 使 macOS(或您的 Linux 系统)更完整。使用 gem 来安装 RubyGems、用 brew 来安装那些依赖包。“要安装,请拖动此图标......”不会再出现了。使用 brew cask 安装 macOS 应用程序、字体和插件以及其他非开源软件。制作一个 cask 就像创建一个配方一样简单。

1.3 Homebrew 简单命令

brew --version brew command[ --verbose| -v] [ options] [ formula]… # Homebrew 安装依赖目录 $ /usr/local/Cellar/ # Homebrew 安装第三方包 $ brew install gnuplot # Homebrew 查询第三方包 $ brew search gnuplot # Homebrew 列举本地机器上已安装的包 $ brew list # Homebrew 卸载第三方包 $ brew uninstall gnuplot

具体各个命令细则,请参考如下 地址:

https://docs.brew.sh/Manpage

 

二. 安装

2.1 WSL 安装

以下安装环境用的是Windows Sub Linux(Ubuntu 18.04 LTS) ,Mac/Linux 安装过程一样的;

继续,

坐等下载 57M 左右的资源...这个过程我等了好久...

网络连接断了,然后继续执行如下语句,重走这个安装过程,

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

然后继续等...

# 首次安装系统后,应执行如下语句 $ sudo apt update

然后继续等...

 

2.2 切换源

然后你会发现巨慢,算了,直接切换清华源吧

参考如下地址:

https://mirror.tuna.tsinghua.edu.cn/help/homebrew/

下载 https://raw.githubusercontent.com/Homebrew/install/master/install.sh 文件命令到本地:

curl https://raw.githubusercontent.com/Homebrew/install/master/install.sh -o install.sh --progress

如果无法下载,或者遇到443 问题,那就直接浏览器中访问https://raw.githubusercontent.com/Homebrew/install/master/install.sh 地址,全选复制保存到新建的 install.sh 文件中;

下载完,修改文件权限,编辑文件,如下命令:

$ ls -al $ chmod 777 install.sh $ vim install.sh

修改内容如下:

BREW_REPO="https://github.com/Homebrew/brew" # 变成: BREW_REPO="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"

如下图所示: 

接着,运行 install.sh 以安装 Homebrew:

HOMEBREW_CORE_GIT_REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git bash install.sh

刚才过程,我走失败了,我重新运行一下,换成国内源后,真香,

 

2.3 配置环境变量

注意到如下所示:

方式一(推荐):

Warning: /home/linuxbrew/.linuxbrew/bin is not in your PATH. ==> 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 (or will be during this `install` run). ==> Homebrew is run entirely by unpaid volunteers. Please consider donating: https://github.com/Homebrew/brew#donations ==> Next steps: - Run `brew help` to get started - Further documentation: https://docs.brew.sh - Install the Homebrew dependencies if you have sudo access: sudo apt-get install build-essential See https://docs.brew.sh/linux for more information - Add Homebrew to your PATH in /home/xxx/.profile: echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >> /home/xxx/.profile eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv) - We recommend that you install GCC: brew install gcc

编辑.profile 文件,

xxx@DESKTOP-XXX:~$ ls -al total 84 drwxr-xr-x 1 xxx xxx 4096 Sep 4 22:06 . drwxr-xr-x 1 root root 4096 Sep 4 22:06 .. -rw------- 1 xxx xxx 823 Sep 4 21:59 .bash_history -rw-r--r-- 1 xxx xxx 220 Sep 4 21:32 .bash_logout -rw-r--r-- 1 xxx xxx 3771 Sep 4 21:32 .bashrc drwxrwxrwx 1 xxx xxx 4096 Sep 4 22:06 .cache drwxr-xr-x 1 xxx xxx 4096 Sep 4 21:32 .landscape -rw-rw-rw- 1 xxx xxx 0 Sep 4 21:32 .motd_shown -rw-r--r-- 1 xxx xxx 807 Sep 4 21:32 .profile // 此处文件 -rw-r--r-- 1 xxx xxx 0 Sep 4 21:42 .sudo_as_admin_successful -rw------- 1 xxx xxx 2394 Sep 4 22:06 .viminfo -rw-rw-rw- 1 xxx xxx 4004 Sep 4 21:53 apt_list_pkg_upgradable.log -rwxr-xr-x 1 xxx xxx 33966 Sep 4 22:06 install.sh

添加如下 语句

eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)

即,

执行如下命令,更新环境变量

source .profile

 

方式二:

 

编辑.bashrc 文件,

添加如下 语句

export LINUX_BREW_HOME=/home/linuxbrew/.linuxbrew export PATH=$LINUX_BREW_HOME/bin:$PATH

即,

执行如下命令,更新环境变量

source .bashrc

即,

 

如果一切都没啥问题的话,执行如下命令:

brew --version

如下所示:

表示,安装成功;

 

2.4 恢复源(可选)

不推荐,国内源相对来说比较快捷,除非万不得已,信息源落后官方源才恢复源去更新;

目前源为清华源:

执行如下命令:

# brew 程序本身,Homebrew/Linuxbrew 相同 git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git # 以下针对 Linux 系统上的 Linuxbrew git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/linuxbrew-core.git ## 如果是Mac 请使用如下 # 以下针对 mac OS 系统上的 Homebrew git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git

如下所示:

使用如下命令,验证一下:

$ brew update Already up-to-date.

如果没啥问题,应该是最新的;

 

三. 参考

https://brew.sh/index_zh-cnhttps://github.com/Homebrew/brewhttps://docs.brew.sh/Formula-Cookbook#homebrew-terminologyhttps://formulae.brew.sh/https://formulae.brew.sh/formula/https://docs.brew.sh/https://docs.brew.sh/Installationhttps://docs.brew.sh/Manpagehttps://docs.brew.sh/Troubleshootinghttps://mirror.tuna.tsinghua.edu.cn/help/homebrew/https://askubuntu.com/questions/759880/where-is-the-ubuntu-file-system-root-directory-in-windows-subsystem-for-linux-an

 

(完)

 

 

 

最新回复(0)