Movatterモバイル変換


[0]ホーム

URL:


Installing JDK on Mac

Multiple ways

Multiple implementors of JDK gives multiple options to instlall JDK for each operating system.In all those installations JDK contents extracted into a directory which makes more sense for the operating system. We can also download the compressed content and extract. It is recommended to choose an approach and stick with it while installing multiple version.

Here are few ways I know of installing JDK

  • Extract zip/tgz
  • Commandline install using brew
  • Commandline install using sdkman
  • GUI install using package

Most prefered/recommended way is the operating system way for end user/developer. Which usually download the package from the JDK vendor and installing with user interface. For Windows, installer executable, for linux yum/rpm packages, for mac app package.

I use brew to install all development related tools/library/kit. So I decided to use it for JDK install as well.

Mac places the Java Virtual Machines under/Library/Java/JavaVirtualMachines folder when installing as mac application. If we are using any other approach, installation recommends us to create symlink to this folder if it installs in other directory.

Here is two output which you can understand this

$/usr/libexec/java_home-V             Matching Java Virtual Machines(4):    17.0.1(x86_64)"Eclipse Temurin" -"Eclipse Temurin 17" /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home    15(x86_64)"AdoptOpenJDK" -"AdoptOpenJDK 15" /Library/Java/JavaVirtualMachines/adoptopenjdk-15.jdk/Contents/Home    11.0.12(arm64)"Homebrew" -"OpenJDK 11.0.12" /opt/homebrew/Cellar/openjdk@11/11.0.12/libexec/openjdk.jdk/Contents/Home    1.8.0_275(x86_64)"AdoptOpenJDK" -"AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home$ls-l /Library/Java/JavaVirtualMachinestotal 0drwxr-xr-x  3 root  wheel  96 Dec 29  2020 adoptopenjdk-15.jdkdrwxr-xr-x  3 root  wheel  96 Nov  9  2020 adoptopenjdk-8.jdklrwxr-xr-x  1 root  wheel  48 Nov 10 07:01 openjdk-11.jdk -> /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdkdrwxr-xr-x  3 root  wheel  96 Sep 15  2021 temurin-17.jdk

Here I installed OpenJDK 11 using homebrew.

Another machine…

$ /usr/libexec/java_home --verboseMatching Java Virtual Machines (6):    18 (x86_64) "Homebrew" - "OpenJDK 18" /usr/local/Cellar/openjdk/18/libexec/openjdk.jdk/Contents/Home    17.0.2 (x86_64) "Eclipse Temurin" - "Eclipse Temurin 17" /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home    15.0.1 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 15" /Library/Java/JavaVirtualMachines/adoptopenjdk-15.jdk/Contents/Home    11.0.5 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 11" /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home    1.8.181.13 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home    1.8.0_151 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/usr/local/Cellar/openjdk/18/libexec/openjdk.jdk/Contents/Home$ pwd/Library/Java/JavaVirtualMachines$ ls -l /Library/Java/JavaVirtualMachinestotal 0drwxr-xr-x  3 root  wheel  96 Jan 15  2020 adoptopenjdk-11.jdkdrwxr-xr-x  3 root  wheel  96 Nov 30  2020 adoptopenjdk-15.jdkdrwxr-xr-x  3 root  wheel  96 Oct 19  2017 jdk1.8.0_151.jdklrwxr-xr-x  1 root  wheel  42 Apr  3 09:30 openjdk.jdk -> /usr/local/opt/openjdk/libexec/openjdk.jdkdrwxr-xr-x  3 root  wheel  96 Jan 20 13:22 temurin-17.jdk

Here I installed OpenJDK 18 using Homebrew. During the install it asked me to symblink (sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk). I dont like the fact that recommendation not specific to version 18.

While you have multiple options to install JDK, Choose the one which you are familiar. If first time choose the operating system way.

Installing JDK 11 using brew

mahendran@mm-lab mahendran % brewinstallopenjdk@11mahendran@mm-lab mahendran %exportJAVA_HOME=$(/usr/libexec/java_home-v11);mahendran@mm-lab mahendran % java-versionopenjdk version"11.0.12" 2021-07-20OpenJDK Runtime Environment Homebrew(build 11.0.12+0)OpenJDK 64-Bit Server VM Homebrew(build 11.0.12+0, mixed mode)

Installing JDK 17 using brew cask

OpenJDK distributions from AdoptOpenJDK now calledEclipse Temurin

mahendran@mm-lab mahendran % brewinstall--cask temurinUpdating Homebrew...==> Auto-updated Homebrew!Updated 3 taps(weaveworks/tap, homebrew/core and homebrew/cask).==> New Formulaekubeval                     pip-tools                   tfmigrate                   tfproviderlint              urlwatch==> Updated FormulaeUpdated 237 formulae.==> Deleted Formulaeamap==> New Casksfotokasten                                     pichon                                         replacicon==> Updated CasksUpdated 186 casks.==> Deleted Casksarmitage                                                              globalmeetWarning: Calling bottle :unneeded is deprecated! There is no replacement.Please report this issue to the weaveworks/tap tap(not Homebrew/brew or Homebrew/core):  /opt/homebrew/Library/Taps/weaveworks/homebrew-tap/Formula/eksctl.rb:9==> Downloading https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.1%2B12/OpenJDK17U-jdk_x64_mac_hotspot_17.0.1_12.p==> Downloading from https://github-releases.githubusercontent.com/372925194/75c5a263-32f3-499c-bb2d-3aee522d0bec?X-Amz-Algorithm=AWS4-HMAC######################################################################## 100.0%==> Installing Cask temurin==> Running installerfortemurin; your password may be necessary.Package installers may write to any location; options such as`--appdir` are ignored.Password:installer: Package name is Eclipse Temurininstaller: Upgrading at base path /installer: The upgrade was successful.🍺  temurin was successfully installed!mahendran@mm-lab mahendran %

Unistalling JDK

We may have installed JDK using different ways. Meaningmanually download dmg and install, viabrew install command or viabrew cask installTo see if it is installed using brew, usebrew list command.To view details about a packagebrew info <package> command

$ brew listadoptopenjdk11  $ brew info adoptopenjdk11adoptopenjdk11: 11.0.9.1,1https://adoptopenjdk.net//usr/local/Caskroom/adoptopenjdk11/11.0.5,10 (180.3MB)From: https://github.com/adoptopenjdk/homebrew-openjdk/blob/HEAD/Casks/adoptopenjdk11.rb==> NameAdoptOpenJDK 11==> DescriptionAdoptOpenJDK OpenJDK (Java) Development Kit==> ArtifactsOpenJDK11U-jdk_x64_mac_hotspot_11.0.9.1_1.pkg (Pkg)

Once we know it is installed via brew, we can unistall usingbrew uninstall <package> command

$ brew uninstall adoptopenjdk==> Uninstalling Cask adoptopenjdk==> Removing directories if empty:Warning: Skipping rmdir for undeletable path '/Library/Java/JavaVirtualMachines'.==> Backing Generic Artifact 'adoptopenjdk-12.0.1.jdk' up to '/usr/local/Caskroom/adoptopenjdk/12.0.1,12/jdk-12.0.1+12'.Password:==> Removing Generic Artifact '/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk'.==> Purging files for version 12.0.1,12 of Cask adoptopenjdk

Uninstall will fail if any dependency on this package (formulae and casks) and you know what you are doing, you may need to force by ignoring dependencies

$ brew uninstall openjdk --ignore-dependenciesUninstalling /usr/local/Cellar/openjdk/15.0.1... (614 files, 324.0MB)

Next Reading Suggestion

Got multiple java version -setup a quick way to switch between java version


[8]ページ先頭

©2009-2025 Movatter.jp