Mac homebrew 简单使用(jdk&maven安装示例)

2020-07-01  本文已影响0人  PC_Repair

Homebrew简称brew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件,可以说Homebrew就是mac下的apt-get、yum神器。


Screenshot 2020-07-01 at 5.03.28 PM.png

Homebrew官网:https://brew.sh/

安装Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
示例1:使用 brew 安装 openjdk

(1)更新库

brew tap AdoptOpenJDK/openjdk

(2)搜索

brew search /adoptopenjdk/
==> Casks
adoptopenjdk                      adoptopenjdk11-openj9-jre         adoptopenjdk12-openj9             adoptopenjdk13-jre                adoptopenjdk14                    adoptopenjdk14-openj9-large       adoptopenjdk8-openj9-jre-large
adoptopenjdk10                    adoptopenjdk11-openj9-jre-large   adoptopenjdk12-openj9-jre         adoptopenjdk13-openj9             adoptopenjdk14-jre                adoptopenjdk8 ✔                   adoptopenjdk8-openj9-large
adoptopenjdk11                    adoptopenjdk11-openj9-large       adoptopenjdk12-openj9-jre-large   adoptopenjdk13-openj9-jre         adoptopenjdk14-openj9             adoptopenjdk8-jre                 adoptopenjdk9
adoptopenjdk11-jre                adoptopenjdk12                    adoptopenjdk12-openj9-large       adoptopenjdk13-openj9-jre-large   adoptopenjdk14-openj9-jre         adoptopenjdk8-openj9
adoptopenjdk11-openj9             adoptopenjdk12-jre                adoptopenjdk13                    adoptopenjdk13-openj9-large       adoptopenjdk14-openj9-jre-large   adoptopenjdk8-openj9-jre

(3)选择一个版本安装

brew cask install adoptopenjdk8

(4)done,默认安装目录是 /Library/Java/JavaVirtualMachines/ , 当然这个目录也会有你安装的其他版本 JDK ,修改下环境变量指向你需要的 JDK 即可。

示例2:使用 brew 安装 maven

(1)搜索并安装 maven

brew search maven
==> Formulae
maven                                  maven-completion                       maven-shell                            maven@3.2                              maven@3.3                              maven@3.5 ✔
==> Casks
mavensmate                                                                     homebrew/cask-fonts/font-maven-pro                                             homebrew/cask-fonts/font-maven-pro-vf-beta
brew install maven@3.5
# 注意安装过程中出现以下输出
...
If you need to have maven@3.5 first in your PATH run:
  echo 'export PATH="/usr/local/opt/maven@3.5/bin:$PATH"' >> ~/.zshrc

(2)配置环境变量

vim ~/.bash_profile

# 加入内容
export PATH=/usr/local/opt/maven@3.5/bin:$PATH

# 使配置文件生效
source ~/.bash_profile

# 验证
mvn -v
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T11:33:14-07:00)
Maven home: /usr/local/Cellar/maven@3.5/3.5.4_1/libexec
Java version: 13.0.2, vendor: N/A, runtime: /usr/local/Cellar/openjdk/13.0.2+8_2/libexec/openjdk.jdk/Contents/Home
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.5", arch: "x86_64", family: "mac"
上一篇下一篇

猜你喜欢

热点阅读