AdSense

網頁

2020/12/1

Mac install Maven by Homebrew

Mac使用Homebrew安裝Maven的方式如下。

範例環境:

  • macOS Catalina
  • Homebrew 2.4.13

在終端機(terminal)輸入brew search maven檢視可供安裝的Maven。

$ brew search maven
==> Formulae
maven                              maven-shell                        maven@3.3
maven-completion                   maven@3.2                          maven@3.5
==> Casks
mavensmate                                           homebrew/cask-fonts/font-maven-pro-vf-beta
homebrew/cask-fonts/font-maven-pro

輸入brew install maven安裝maven。安裝前會先另外安裝maven運行需要的JDK (即使你的電腦中已經有JDK也仍會安裝)。

$ brew install maven
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/openjdk-15.0.1.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/9376a1c6fdf8b0268b6cb56c9878358df148b530fcb0e3
######################################################################## 100.0%
==> Downloading https://www.apache.org/dyn/closer.lua?path=maven/maven-3/3.6.3/binaries/apache-maven-3.6.
==> Downloading from https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar
######################################################################## 100.0%
==> Installing dependencies for maven: openjdk
==> Installing maven dependency: openjdk
==> Pouring openjdk-15.0.1.catalina.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into /usr/local,
because it shadows the macOS `java` wrapper.

If you need to have openjdk first in your PATH run:
  echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> /Users/user/.bash_profile

For compilers to find openjdk you may need to set:
  export CPPFLAGS="-I/usr/local/opt/openjdk/include"

==> Summary
🍺  /usr/local/Cellar/openjdk/15.0.1: 614 files, 324.9MB
==> Installing maven
🍺  /usr/local/Cellar/maven/3.6.3_1: 87 files, 10.7MB, built in 2 seconds

安裝前Homebrew會先更新已安裝套件的依賴,如果更新過程中卡住可以按control + C終止然後再重新輸入一次安裝指令看看。

安裝完後輸入mvn -v如果有顯示版本資訊即安裝成功。

$ mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 15.0.1, vendor: N/A, runtime: /usr/local/Cellar/openjdk/15.0.1/libexec/openjdk.jdk/Contents/Home
Default locale: en_TW, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.5", arch: "x86_64", family: "mac"

輸入brew list即可看到安裝的maven。

$ brew list
ant     maven    openjdk

輸入brew info maven查看安裝的maven資訊。

$ brew info maven
maven: stable 3.6.3
Java-based project management
https://maven.apache.org/
Conflicts with:
  mvnvm (because also installs a 'mvn' executable)
/usr/local/Cellar/maven/3.6.3_1 (87 files, 10.7MB) *
  Built from source on 2020-12-01 at 17:20:21
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/maven.rb
License: Apache-2.0
==> Dependencies
Required: openjdk ✔
==> Analytics
install: 30,530 (30 days), 94,283 (90 days), 480,788 (365 days)
install-on-request: 30,047 (30 days), 92,695 (90 days), 463,811 (365 days)
build-error: 0 (30 days)

Maven local repository預設位置在/Users/<user>/.m2<user>為使用者目錄,.m2為隱藏的資料夾。

沒有留言:

AdSense