網頁

2020/8/25

Mac install JDK by Homebrew

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


範例環境:

  • macOS Catalina version 10.15.5
  • Homebrew 2.4.13

Mac中已經有JDK 8,透過Homebrew安裝JDK 11。

在終端機輸入brew tap homebrew/cask-version安裝Homebrew Cask的可選版本repository。

$ brew tap homebrew/cask-versions
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
cdktf                                                    mhonarc                                                  protoc-gen-gogofaster
==> Updated Formulae
Updated 16 formulae.
==> Updated Casks
aerial                  cockatrice              flipper                 http-toolkit            kotlin-native           podman                  ultimaker-cura
alt-tab                 downie                  forklift                intellij-idea           kui                     pyfa                    visual-studio-code
amazon-chime            dropbox                 gifox                   intellij-idea-ce        mattermost              sensei                  webstorm
backblaze               filemaker-pro           google-chrome           jettison                mpv                     sketch                  zeebe-modeler
bot-framework-emulator  firefox                 hiddenbar               kext-updater            onyx                    soulver

==> Tapping homebrew/cask-versions
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-versions'...
remote: Enumerating objects: 86, done.
remote: Counting objects: 100% (86/86), done.
remote: Compressing objects: 100% (67/67), done.
remote: Total 228477 (delta 46), reused 37 (delta 19), pack-reused 228391
Receiving objects: 100% (228477/228477), 58.83 MiB | 1.87 MiB/s, done.
Resolving deltas: 100% (157241/157241), done.
Tapped 159 casks (205 files, 65.2MB).

輸入brew search java查詢有哪些版本可以安裝。

$ brew search java
==> Formulae
app-engine-java                   java                              javacc                            jslint4java                       pdftk-java
google-java-format                java11                            javarepl                          libreadline-java
==> Casks
charles-applejava                 eclipse-javascript                java-beta                         java6                             netbeans-java-se
eclipse-java                      java                              java11                            netbeans-java-ee                  oracle-jdk-javadoc

輸入brew cask info java11檢視Cask的java11資訊。

$ brew cask info java11
java11: 11.0.2,9
https://www.oracle.com/technetwork/java/javase/
Not installed
From: https://github.com/Homebrew/homebrew-cask-versions/blob/HEAD/Casks/java11.rb
==> Name
OpenJDK Java Development Kit
==> Description
None
==> Artifacts
jdk-11.0.2.jdk -> /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk (Generic Artifact)

可以看到Cask的java11是OpenJDK。

輸入brew cask install java11開始安裝,安裝中會要求輸入系統管理員密碼。

$ brew cask install java11
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
==> Updated Casks
fantastical                 ilok-license-manager        maccy                       pagico                      permute                     youku
framer                      loom                        nordvpn                     parallels-toolbox           screen

==> Downloading https://download.oracle.com/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'java11'.
==> Installing Cask java11
==> Moving Generic Artifact 'jdk-11.0.2.jdk' to '/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk'.
Password:
🍺  java11 was successfully installed!

安裝完後輸入/usr/libexec/java_home -V查看Mac已安裝的JDK,可以看到多了OpenJDK 11.0.2

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    11.0.2, x86_64:	"OpenJDK 11.0.2"	/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home
    1.8.0_251, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home

輸入java --version查看目前使用的Java版本已變成剛安裝的OpenJDK 11。

$ java -version
openjdk 11.0.2 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

若文章對您有幫助還幫忙點個廣告,謝謝您的支持。


沒有留言:

張貼留言