Home Archives Categories Tags Docs

Mac Brew 介绍

发布时间: 更新时间: 总字数:615 阅读时间:2m 作者: 分享

Homebrew是一款Mac OS上的软件包管理工具,通过它可以很方便的安装/卸载软件工具等,类似于Linux下的apt-get,node的npm等包管理工具。

安装

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

使用

  • brew cask search java
  • brew cask info java
  • brew cask install java

安装包

brew install wget

java 安装

默认安装 openjdk

# brew cask install java
==> Satisfying dependencies
==> Downloading https://download.oracle.com/java/GA/jdk12.0.1/69cfe15208a647278a19ef0990eea691/12
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'java'.
==> Installing Cask java
==> Moving Generic Artifact 'jdk-12.0.1.jdk' to '/Library/Java/JavaVirtualMachines/openjdk-12.0.1
Password:
🍺  java was successfully installed!
# bak java --version
openjdk 12.0.1 2019-04-16
OpenJDK Runtime Environment (build 12.0.1+12)
OpenJDK 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)

keybase 安装

brew cask install java

iproute2mac

提供 Linuxss 等工具集:

brew install iproute2mac

配置 homebrew 阿里源

替换brew.git

cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 应用生效
brew update

## 替换homebrew-bottles:
## Bash 终端
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

## Zsh 终端配置
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

恢复默认配置

# 重置brew.git:
$ cd "$(brew --repo)"
$ git remote set-url origin https://github.com/Homebrew/brew.git
# 重置homebrew-core.git:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git remote set-url origin https://github.com/Homebrew/homebrew-core.git

然后把 ~/.bash_profile~/.zshrc 中的 HOMEBREW_BOTTLE_DOMAINsource 文件生效。

问题

brew 和 brew cask

  • brew 是从下载源码解压然后 ./configure && make install ,同时会包含相关依存库。并自动配置好各种环境变量,而且易于卸载。简单的指令,就能快速安装和升级本地的各种开发环境。
  • brew cash 是已经编译好了的应用包 (.dmg/.pkg),仅仅是下载解压,放在统一的目录中(/opt/homebrew-cask/Caskroom),省掉了自己去下载、解压、拖拽(安装)等蛋疼步骤,同样,卸载相当容易与干净。这个对一般用户来说会比较方便,包含很多在 App Store 里没有的常用软件。






参考