Mac 安装使用 brew 包管理器

brew 介绍

brew 是 Mac 下的一个包管理工具,类似于 centos 下的 yum,可以很方便地进行安装 / 卸载 / 更新各种软件包,例如:nodejs, elasticsearch, kibana, mysql, mongodb 等等,可以用来快速搭建各种本地环境,程序员必备工具

  • 官网:https://brew.sh/index_zh-cn.htm

安装 brew

打开终端,可以使用如下命令安装 brew:

% /bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)

如下所示:

hellojue@192 ~ % /bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
==> Checking for `sudo` access (which may request your password).
Password:
==> This script will install:
==> 安装提示
中文安装教程(建议收藏):https://brew.idayer.com/
如果你想换源,可以使用镜像助手:https://brew.idayer.com/guide/change-source/
…………
Warning: !!!!!!!!!!! 重要  !!!!!!!!!!!!!!!
Warning: 看到此提示,一定要执行 Next steps 中的 环境变量设置!!!
Warning: /opt/homebrew/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:
Warning: !!!!!!!!!!! 重要  !!!!!!!!!!!!!!!
切记执行环境变量设置!,如已执行过请忽略。
- 执行下面命令将 Homebrew 到 PATH 中:
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/hellojue/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
  如有疑问,可以访问 https://brew.idayer.com/guide/m1/
- 🎉 恭喜,安装成功!运行 `brew help` 开始体验吧
- 更多文档: 
    https://docs.brew.sh
    https://brew.idayer.com

加入环境变量

此时,执行 brew 命令依然没有反应。

hellojue@192 ~ % brew
zsh: command not found: brew

需要加入环境变量;

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/hellojue/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

验证安装:

% brew -v
Homebrew 3.5.6
Homebrew/homebrew-core (git revision 094a04d5fab; last commit 2022-07-22)

通过 brew 安装软件

安装 node

brew install node

安装 OpenVPN

安装 OpenVPN,安装完成后需要重启 openVPN 服务:

% To restart openvpn after an upgrade:
  sudo brew services restart openvpn
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/openvpn/sbin/openvpn --config /opt/homebrew/etc/openvpn/openvpn.conf

安装 mark-text

brew install --cask mark-text

安装 enca

brew install enca

安装 python

brew install python

验证:

% python3 --version
Python 3.9.13

可配置 vim ~/.zshrc ,添加 alias python=python3,然后 source ~/.zshrc

查看 brew 安装列表

% brew list
==> Formulae
berkeley-db    icu4c        lzo        perl        sqlite
brotli        libnghttp2    mpdecimal    pkcs11-helper    vim
c-ares        libuv        ncurses        python@3.10    xz
ca-certificates    libyaml        node        python@3.9
gdbm        lua        openssl@1.1    readline
gettext        lz4        openvpn        ruby

通过 brew 卸载软件

brew uninstall openvpn --force