Mac 下 使用 HomeBrew 管理第三方软件包

2018-11-30  本文已影响0人  古城老叫

1. HomeBrew 是什么

为什么 Mac 没有,还是我不知道?相信任何受大众所接受的系统都绝非这样不堪;况且,给我一颗卫星又如何,我能把它飞起来给你搞直播小电影么?既是小白,那就应该有小白的态度,谦虚、谨慎、勤学、好问。

问谁?
问 google 啊!反正别问百度,坑死你没商量,检索结果是否优质不说,就广告都能让你烦死。

遂,google 之,HomeBrew 引入眼帘... ...

macOS 缺失的软件包的管理器
安装 Apple 没有预装但你需要的东西

正如官网所说的那样:使用 Homebrew 安装 Apple 没有预装但 你需要的东西(动手点一下看你需要啥?)
还是中文?从此妈妈再也不用担心我干活找不到软件包了

2. 如何安装 HomeBrew

言归正传,现在开始安装 HomeBrew。


安装 HomeBrew

遂,执行之:

Mac-mini:~ pancras$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443
Mac-mini:~ pancras$

报错,报错,报错,伟大的GFW,再一次我被你拒之门内... ...


启用终端代理

翻墙走一波...

Mac-mini:~ pancras$ export http_proxy=http://127.0.0.1:1087;export https_proxy=http://127.0.0.1:1087;

顺利执行!

wangpankundeMac-mini:~ pancras$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew

Press RETURN to continue or any other key to abort

提示按回车键继续,按其他键取消,你知道该怎么选!

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew
Password:

提示输入密码继续执行

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown pancras /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Enumerating objects: 215, done.
remote: Counting objects: 100% (215/215), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 224 (delta 195), reused 215 (delta 195), pack-reused 9
Receiving objects: 100% (224/224), 31.36 KiB | 10.45 MiB/s, done.
Resolving deltas: 100% (195/195), completed with 173 local objects.
From https://github.com/Homebrew/brew
   2063a8a4d..30c90dcc3  master     -> origin/master
 * [new tag]             1.8.4      -> 1.8.4
HEAD is now at 30c90dcc3 Merge pull request #5359 from claui/tls-coming-home

等待脚本命令执行完毕后,会看到如下界面:

==> 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
==> 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

大功告成,是不是很简单?

提示:为什么要翻墙才能顺利安装?
HomeBrew 安装软件包有时会从国外的网站下载依赖资源,恰巧所访问的资源网站被GFW给屏蔽了,此时需要开启代理才可以正确下载资源,正如你访问 Github 和 google 一样,不开代理永远止步于国内!

3. 如何使用 HomeBrew 安装软件

安装完 HomeBrew 后可使用以下命令进行软件包安装:

brew install 软件名称

下文以安装 mysql 为例:

Mac-mini:~ pancras$ brew install mysql
==> Installing dependencies for mysql: openssl
==> Installing mysql dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2q.mojave.bottl
######################################################################## 100.0%
==> Pouring openssl-1.0.2q.mojave.bottle.tar.gz
... 省略若干 ...
==> mysql
We've installed your MySQL database without a root password. To secure it run:mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:mysql -uroot
To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start

根据提示可以看到,若需要以服务的方式后台运行并开机启动需执行以下命令:

brew services start mysql

若您不需后台运行服务,执行以下命令即可:

  $ mysql.server start

是不是很简单?大功告成!

4. HomeBrew 常用命令

$ brew --help    # 查看简洁帮助
$ man brew     # 完整命令帮助
$ brew install [name]    # 安装软件包
$ brew uninstall [name]    # 卸载软件包
$ brew search [name]    # 搜索软件包
$ brew list    # 显示已经安装的所有软件包
$ brew update    # 同步远程最新更新情况,对本机已经安装并有更新的软件用*标明
$ brew outdated    # 查看已安装的哪些软件包需要更新
$ brew upgrade [name]    # 更新单个软件包
$ brew info [name]    # 查看软件包信息
$ brew home [name]    # 访问软件包官方站
$ brew cleanup    # 清理所有已安装软件包的历史老版本
$ brew cleanup [name]    # 清理单个已安装软件包的历史版本

提示:本文所使用的翻墙工具是 ShadowsocksNG,科学上网利器,作为一个 coder 这是必不可少的,后面会推出 ShadowsocksNG 安装教程。

上一篇下一篇

猜你喜欢

热点阅读