Skip to main content
adding link to another answer in SE (Stack sites), to set Env Vars in MacOS
Source Link
atErik
  • 201
  • 2
  • 8
  • in macOS-X Catalina (or macOS-XI/11/X1 after it), obtain the "openjdk*.tar.gz" archive-file (not dmg/zip) from OpenJDK.Java.net or its archive-page, (make sure you see "https" (or Locked-Lock-symbol) in web-browser when you download) . Then verify/compare downloaded file's authenticity/integrity : you may use hash/digest SHA256 code shown on openjdk site, Use openssl tool in Terminal utility : with such command: openssl sha256 & then drag the openjdk*.tar.gz file from Finder into that openssl command-line in Terminal, press enter to compute hash/digest, then Compare computed SHA256 digest-code with sha256 what is shown on https://OpenJDK.Java.net/ secure webpage, both must match/same,
  • double-click on "openjdk*.tar.gz" (to decompress it) in Finder , MacOS may show notice & stop that,
  • Open your "System-Preferences" > "Security & Privacy" > under "General" tab > goto bottomside section "Allow Apps Downloaded From" > press the "Allow" or "Open anyway" button there to allow the decompression of "openjdk*.tar.gz" archive-file (macOS will ask to enter Password of a privileged Admin type account), then it should decompress , if it does not decompress then again double tap on the "openjdk*.tar.gz" file in Finder, & choose "Open"/"Allow" button if macOS asks you again , then it will finally decompress that "*.tar.gz" file, & extract a folder from it,
  • copy that newly extracted/decompressed OpenJDK folder "jdk*.jdk" , & goto below destination folder & MOVE (to move use the "alt/option" button to change the "paste" mode into "move" mode) the "jdk*.jdk" folder inside below destination location:
    "/Library/Java/JavaVirtualMachines/"
    macOS will ask again to enter a privileged accnt Password, do that to complete the move.
  • open Terminal , run this command: /usr/libexec/java_home
    if output contains+shows : "/Library/Java/JavaVirtualMachines/jdk-*.jdk/Contents/Home" , where * will actually show the Java version number, then its good.
  • in Terminal, run this long command-set:
    echo '#!/bin/bash' > ~/TestJava.sh ; echo "export JAVA_HOME=\"\$(/usr/libexec/java_home --version 14.0)\";" >> ~/TestJava.sh ; echo "export PATH=\"\$JAVA_HOME/bin:\$PATH\";" >> ~/TestJava.sh ; echo "java -version ;" >> ~/TestJava.sh ; chmod +x ~/TestJava.sh ; ~/TestJava.sh
    if you want to avoid above long command-set, then run below shorter command:
    $($(/usr/libexec/java_home --version 14.0)/bin/java -version)
    macOS will ask you to enter a privileged accnt + Password again, do that, & choose "Open"/"Allow", then you should see output like this:
         openjdk 14.0.1 2020-04-14
         OpenJDK Runtime Environment (build 14.0.1+7)
         OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
    (at the time of writing this answer i used openjdk 14.0.1, so above output shows those . if you're using Java 13, & if you want to use long command-set shown above then run this nano command after that: nano ~/TestJava.sh , & change the line which has version number 14.0, into 13.0 , if you want to use a shorter command which is also shown in above, then (also for this) just change the 14.0 into 13.0)
  • Done . From this point-on, you will-not/should-not see any-other blocks/locks from macOS for using/running that java.

OPTIONAL STEP : if you want-to & need-to, then before running a java-based App, either setup the JAVA_HOME env var globally (to apply same Java on all java-based apps), or Use a shell-script to setup a specific Java to run a specific java-based App . A sample of such shell script is already shown in above long command-set , suit/change/modify that to your needs . if you want-to then follow this(goto bottom-side "Optional : Java ENV VAR" section) or this(recommended) or this or any other better instructions.

  • in macOS-X Catalina (or macOS-XI/11/X1 after it), obtain the "openjdk*.tar.gz" archive-file (not dmg/zip) from OpenJDK.Java.net or its archive-page, (make sure you see "https" (or Locked-Lock-symbol) in web-browser when you download) . Then verify/compare downloaded file's authenticity/integrity : you may use hash/digest SHA256 code shown on openjdk site, Use openssl tool in Terminal utility : with such command: openssl sha256 & then drag the openjdk*.tar.gz file from Finder into that openssl command-line in Terminal, press enter to compute hash/digest, then Compare computed SHA256 digest-code with sha256 what is shown on https://OpenJDK.Java.net/ secure webpage,
  • double-click on "openjdk*.tar.gz" (to decompress it) in Finder , MacOS may show notice & stop that,
  • Open your "System-Preferences" > "Security & Privacy" > under "General" tab > goto bottomside section "Allow Apps Downloaded From" > press the "Allow" or "Open anyway" button there to allow the decompression of "openjdk*.tar.gz" archive-file (macOS will ask to enter Password of a privileged Admin type account), then it should decompress , if it does not decompress then again double tap on the "openjdk*.tar.gz" file in Finder, & choose "Open"/"Allow" button if macOS asks you again , then it will finally decompress that "*.tar.gz" file, & extract a folder from it,
  • copy that newly extracted/decompressed OpenJDK folder "jdk*.jdk" , & goto below destination folder & MOVE (to move use the "alt/option" button to change the "paste" mode into "move" mode) the "jdk*.jdk" folder inside below destination location:
    "/Library/Java/JavaVirtualMachines/"
    macOS will ask again to enter a privileged accnt Password, do that to complete the move.
  • open Terminal , run this command: /usr/libexec/java_home
    if output contains+shows : "/Library/Java/JavaVirtualMachines/jdk-*.jdk/Contents/Home" , where * will actually show the Java version number, then its good.
  • in Terminal, run this long command-set:
    echo '#!/bin/bash' > ~/TestJava.sh ; echo "export JAVA_HOME=\"\$(/usr/libexec/java_home --version 14.0)\";" >> ~/TestJava.sh ; echo "export PATH=\"\$JAVA_HOME/bin:\$PATH\";" >> ~/TestJava.sh ; echo "java -version ;" >> ~/TestJava.sh ; chmod +x ~/TestJava.sh ; ~/TestJava.sh
    if you want to avoid above long command-set, then run below shorter command:
    $($(/usr/libexec/java_home --version 14.0)/bin/java -version)
    macOS will ask you to enter a privileged accnt + Password again, do that, & choose "Open"/"Allow", then you should see output like this:
     openjdk 14.0.1 2020-04-14
     OpenJDK Runtime Environment (build 14.0.1+7)
     OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
    (at the time of writing this answer i used openjdk 14.0.1, so above output shows those . if you're using Java 13, & if you want to use long command-set shown above then run this nano command after that: nano ~/TestJava.sh , & change the line which has version number 14.0, into 13.0 , if you want to use a shorter command which is also shown in above, then (also for this) just change the 14.0 into 13.0)
  • Done . From this point-on, you will-not/should-not see any-other blocks/locks from macOS for using/running that java.

OPTIONAL STEP : if you want-to then before running a java-based App, either setup the JAVA_HOME env var globally (to apply same Java on all java-based apps), or Use a shell-script to setup a specific Java to run a specific App . A sample of such shell script is shown in above long command-set . if you want-to then follow this(goto bottom-side "Optional : Java ENV VAR" section) or this or any other better instructions.

  • in macOS-X Catalina (or macOS-XI/11/X1 after it), obtain the "openjdk*.tar.gz" archive-file (not dmg/zip) from OpenJDK.Java.net or its archive-page, (make sure you see "https" (or Locked-Lock-symbol) in web-browser when you download) . Then verify/compare downloaded file's authenticity/integrity : you may use hash/digest SHA256 code shown on openjdk site, Use openssl tool in Terminal utility : with such command: openssl sha256 & then drag the openjdk*.tar.gz file from Finder into that openssl command-line in Terminal, press enter to compute hash/digest, then Compare computed SHA256 digest-code with sha256 what is shown on https://OpenJDK.Java.net/ secure webpage, both must match/same,
  • double-click on "openjdk*.tar.gz" (to decompress it) in Finder , MacOS may show notice & stop that,
  • Open your "System-Preferences" > "Security & Privacy" > under "General" tab > goto bottomside section "Allow Apps Downloaded From" > press the "Allow" or "Open anyway" button there to allow the decompression of "openjdk*.tar.gz" archive-file (macOS will ask to enter Password of a privileged Admin type account), then it should decompress , if it does not decompress then again double tap on the "openjdk*.tar.gz" file in Finder, & choose "Open"/"Allow" button if macOS asks you again , then it will finally decompress that "*.tar.gz" file, & extract a folder from it,
  • copy that newly extracted/decompressed OpenJDK folder "jdk*.jdk" , & goto below destination folder & MOVE (to move use the "alt/option" button to change the "paste" mode into "move" mode) the "jdk*.jdk" folder inside below destination location:
    "/Library/Java/JavaVirtualMachines/"
    macOS will ask again to enter a privileged accnt Password, do that to complete the move.
  • open Terminal , run this command: /usr/libexec/java_home
    if output contains+shows : "/Library/Java/JavaVirtualMachines/jdk-*.jdk/Contents/Home" , where * will actually show the Java version number, then its good.
  • in Terminal, run this long command-set:
    echo '#!/bin/bash' > ~/TestJava.sh ; echo "export JAVA_HOME=\"\$(/usr/libexec/java_home --version 14.0)\";" >> ~/TestJava.sh ; echo "export PATH=\"\$JAVA_HOME/bin:\$PATH\";" >> ~/TestJava.sh ; echo "java -version ;" >> ~/TestJava.sh ; chmod +x ~/TestJava.sh ; ~/TestJava.sh
    if you want to avoid above long command-set, then run below shorter command:
    $($(/usr/libexec/java_home --version 14.0)/bin/java -version)
    macOS will ask you to enter a privileged accnt + Password again, do that, & choose "Open"/"Allow", then you should see output like this:
        openjdk 14.0.1 2020-04-14
        OpenJDK Runtime Environment (build 14.0.1+7)
        OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
    (at the time of writing this answer i used openjdk 14.0.1, so above output shows those . if you're using Java 13, & if you want to use long command-set shown above then run this nano command after that: nano ~/TestJava.sh , & change the line which has version number 14.0, into 13.0 , if you want to use a shorter command which is also shown in above, then (also for this) just change the 14.0 into 13.0)
  • Done . From this point-on, you will-not/should-not see any-other blocks/locks from macOS for using/running that java.

OPTIONAL STEP : if you want-to & need-to, then before running a java-based App, either setup the JAVA_HOME env var globally (to apply same Java on all java-based apps), or Use a shell-script to setup a specific Java to run a specific java-based App . A sample of such shell script is already shown in above long command-set , suit/change/modify that to your needs . if you want-to then follow this(goto bottom-side "Optional : Java ENV VAR" section) or this(recommended) or this or any other better instructions.

clarifying difference of OpenJDK-Java & Oracle Java
Source Link
atErik
  • 201
  • 2
  • 8

OpenJDK Java (includes JRE) is open-source, & freeit is FREE for any Commercial & any deployment/distribution & any Personal usage.
JavaOracle Java (JDK) from Oracle (includes Oracle JRE) has OpenJDK & closed-source/proprietary components, & it is free foronly-for Personal usage, a paid License required for any Commercial usage & for any deployment/distribution, & all users also must do a (free) web-registration required to download. For Commercial usage contact Oracle to obtain commercial any binary/paid Licensesource. You may see this too.

  • in macOS-X Catalina (or macOS-XI/11/X1 after it), obtain the "openjdk*.tar.gz" archive-file (not dmg/zip) from OpenJDK.Java.net or its archive-site-page, (make sure you see "https" (or Locked-Lock-symbol) in web-browser when you download)  . Then verify/compare downloaded file's authenticity/integrity, : you may use hash/digest SHA256 code shown on openjdk site, Use openssl tool in Terminal utility : with such command: openssl sha256 & then drag the openjdk*.tar.gz file from Finder into that openssl command-line in Terminal, press enter to compute hash/digest, then Compare computed SHA256 digest-code with sha256 what is shown on https://OpenJDK.Java.net/ secure webpage,
  • double-click on it"openjdk*.tar.gz" (to decompress it) in Finder , MacOS may show notice & stop that,
  • Open your "System-Preferences""System-Preferences" > "Security & Privacy""Security & Privacy" > under "General" tab > goto bottomside section "Allow Apps Downloaded From""Allow Apps Downloaded From" > press the "Allow" or "Open anyway""Open anyway" button there to allow the decompression of "openjdk*.tar.gz" archive-file (macOS may/willwill ask to enter Password of a privileged Admin type account), then it should decompress , if it does not decompress then again double tap on the "openjdk*.tar.gz" file in Finder, & choose "Open""Open"/"Allow" button if macOS asks you again , then it will finally decompress that "*.tar.gz" file, & extract a folder from it,
  • copy the newthat newly extracted/decompressed OpenJDK folder "jdk*.jdk" , & goto below destination folder & moveMOVE (to move use the "alt/option" button: to change the "paste" will changemode into "move" mode) the "jdk*.jdk" folder inside thisbelow destination location:
    "/Library/Java/JavaVirtualMachines/"
    macOS will ask again to enter a privileged accnt Password, do that to complete the move.
  • open Terminal , run this command: /usr/libexec/java_home
    if output contains+shows : "/Library/Java/JavaVirtualMachines/jdk-*.jdk/Contents/Home" , where * will actually show your installedthe Java version number, then its good.
  • in Terminal, run this long command-set:
    echo '#!/bin/bash' > ~/TestJava.sh ; echo "export JAVA_HOME=\"\$(/usr/libexec/java_home --version 14.0)\";" >> ~/TestJava.sh ; echo "export PATH=\"\$JAVA_HOME/bin:\$PATH\";" >> ~/TestJava.sh ; echo "java -version ;" >> ~/TestJava.sh ; chmod +x ~/TestJava.sh ; ~/TestJava.sh
    if you want to avoid above long command-set, then run thisbelow shorter command:
    $($(/usr/libexec/java_home --version 14.0)/bin/java -version)
    macOS will ask you to enter a privileged accnt + Password again, do that, & choose "Open""Open"/"Allow", then you should see output like this:
    openjdk 14.0.1 2020-04-14
    OpenJDK Runtime Environment (build 14.0.1+7)
    OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
    (at the time of writing this answer i used openjdk 14.0.1, so above output shows those . if you're using Java 13, & if you want to use long command-set shown above then run this nano command after that: nano ~/TestJava.sh , & change the line which has version number 14.0, into 13.0 , if you want to use a shorter command which is also shown in above, then (also for this) just change the "1414.0"0 into "1313.0"0)
  • Done . From this point-on, you will-not/should-not see any-other blocks/locks from macOS for using/running that java.

OPTIONAL STEP : if you want-to then before running a java-based App, either setup the JAVA_HOME env var globally (to apply same Java on all java-based apps), or Use a shell-script to setup a specific Java to run a specific App . A sample of such shell script is shown in above long command-set . if you want-to then follow this(goto bottom-side "Optional : Java ENV VAR" section) or this or any other better instructions.

OPTIONAL STEP : you can see all installed Java versions with: /usr/libexec/java_home -V
(you should see your installed version on the displayed list)

OpenJDK (includes JRE) is open-source & free for Commercial & Personal usage.
Java (JDK) from Oracle (includes Oracle JRE) is free for Personal usage, & web-registration required to download. For Commercial usage contact Oracle to obtain commercial/paid License. You may see this too.

  • in macOS-X Catalina (or macOS-XI/11/X1 after it), obtain the "openjdk*.tar.gz" archive-file (not dmg/zip) from OpenJDK.Java.net or its archive-site, (make sure you see "https" (or Locked-Lock-symbol) in web-browser when you download). Then verify/compare downloaded file's authenticity/integrity, you may use hash/digest SHA256 code shown on openjdk site, Use openssl tool in Terminal utility : with such command: openssl sha256 & then drag the openjdk*.tar.gz file from Finder into that openssl command-line in Terminal, press enter to compute hash/digest, then Compare computed digest with what is shown on https://OpenJDK.Java.net/ secure webpage,
  • double-click on it (to decompress it) in Finder , MacOS may show notice & stop that,
  • Open your "System-Preferences" > "Security & Privacy" > under "General" tab > goto bottomside section "Allow Apps Downloaded From" > press the "Allow" or "Open anyway" button there to allow the decompression of "openjdk*.tar.gz" archive-file (macOS may/will ask to enter Password of a privileged Admin type account), then it should decompress , if it does not then again double tap on the "openjdk*.tar.gz" in Finder, & choose "Open"/"Allow" button if macOS asks you again , then it will finally decompress that "*.tar.gz" file,
  • copy the new OpenJDK folder "jdk*.jdk" , & goto below destination folder & move (to move use "alt/option" button: the "paste" will change into "move") the "jdk*.jdk" folder inside this destination location:
    "/Library/Java/JavaVirtualMachines/"
    macOS will ask again to enter a privileged accnt Password, do that to complete the move.
  • open Terminal , run this command: /usr/libexec/java_home
    if output contains+shows : "/Library/Java/JavaVirtualMachines/jdk-*.jdk/Contents/Home" , where * will actually show your installed Java version number, then its good.
  • in Terminal, run this long command-set:
    echo '#!/bin/bash' > ~/TestJava.sh ; echo "export JAVA_HOME=\"\$(/usr/libexec/java_home --version 14.0)\";" >> ~/TestJava.sh ; echo "export PATH=\"\$JAVA_HOME/bin:\$PATH\";" >> ~/TestJava.sh ; echo "java -version ;" >> ~/TestJava.sh ; chmod +x ~/TestJava.sh ; ~/TestJava.sh
    if you want to avoid above long command-set, then run this shorter command:
    $($(/usr/libexec/java_home --version 14.0)/bin/java -version)
    macOS will ask you to enter a privileged accnt + Password again, do that, & choose "Open"/"Allow", then you should see output like this:
    openjdk 14.0.1 2020-04-14
    OpenJDK Runtime Environment (build 14.0.1+7)
    OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
    (at the time of writing this answer i used openjdk 14.0.1, so above output shows those . if you're using Java 13, & if you want to use long command-set shown above then run this nano command after that: nano ~/TestJava.sh & change the line which has version number 14.0, into 13.0 , if you want to use a shorter command which is also shown in above, then (also for this) just change the "14.0" into "13.0")
  • Done . From this point-on, you will-not/should-not see any-other blocks/locks from macOS for using/running that java.

OPTIONAL STEP : if you want-to then before running a java-based App, either setup the JAVA_HOME env var globally, or Use a shell-script to setup a specific Java to run a specific App . A sample of such shell script is shown in above long command-set . if you want-to then follow this(goto bottom-side "Optional : Java ENV VAR" section) or this or any other better instructions.

OPTIONAL STEP : you can see all installed Java versions with: /usr/libexec/java_home -V

OpenJDK Java (includes JRE) is open-source, & it is FREE for any Commercial & any deployment/distribution & any Personal usage.
Oracle Java (JDK) (includes JRE) has OpenJDK & closed-source/proprietary components, & it is free only-for Personal usage, a paid License required for any Commercial usage & for any deployment/distribution, & all users also must do a (free) web-registration to download any binary/source. You may see this too.

  • in macOS-X Catalina (or macOS-XI/11/X1 after it), obtain the "openjdk*.tar.gz" archive-file (not dmg/zip) from OpenJDK.Java.net or its archive-page, (make sure you see "https" (or Locked-Lock-symbol) in web-browser when you download)  . Then verify/compare downloaded file's authenticity/integrity : you may use hash/digest SHA256 code shown on openjdk site, Use openssl tool in Terminal utility : with such command: openssl sha256 & then drag the openjdk*.tar.gz file from Finder into that openssl command-line in Terminal, press enter to compute hash/digest, then Compare computed SHA256 digest-code with sha256 what is shown on https://OpenJDK.Java.net/ secure webpage,
  • double-click on "openjdk*.tar.gz" (to decompress it) in Finder , MacOS may show notice & stop that,
  • Open your "System-Preferences" > "Security & Privacy" > under "General" tab > goto bottomside section "Allow Apps Downloaded From" > press the "Allow" or "Open anyway" button there to allow the decompression of "openjdk*.tar.gz" archive-file (macOS will ask to enter Password of a privileged Admin type account), then it should decompress , if it does not decompress then again double tap on the "openjdk*.tar.gz" file in Finder, & choose "Open"/"Allow" button if macOS asks you again , then it will finally decompress that "*.tar.gz" file, & extract a folder from it,
  • copy that newly extracted/decompressed OpenJDK folder "jdk*.jdk" , & goto below destination folder & MOVE (to move use the "alt/option" button to change the "paste" mode into "move" mode) the "jdk*.jdk" folder inside below destination location:
    "/Library/Java/JavaVirtualMachines/"
    macOS will ask again to enter a privileged accnt Password, do that to complete the move.
  • open Terminal , run this command: /usr/libexec/java_home
    if output contains+shows : "/Library/Java/JavaVirtualMachines/jdk-*.jdk/Contents/Home" , where * will actually show the Java version number, then its good.
  • in Terminal, run this long command-set:
    echo '#!/bin/bash' > ~/TestJava.sh ; echo "export JAVA_HOME=\"\$(/usr/libexec/java_home --version 14.0)\";" >> ~/TestJava.sh ; echo "export PATH=\"\$JAVA_HOME/bin:\$PATH\";" >> ~/TestJava.sh ; echo "java -version ;" >> ~/TestJava.sh ; chmod +x ~/TestJava.sh ; ~/TestJava.sh
    if you want to avoid above long command-set, then run below shorter command:
    $($(/usr/libexec/java_home --version 14.0)/bin/java -version)
    macOS will ask you to enter a privileged accnt + Password again, do that, & choose "Open"/"Allow", then you should see output like this:
    openjdk 14.0.1 2020-04-14
    OpenJDK Runtime Environment (build 14.0.1+7)
    OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
    (at the time of writing this answer i used openjdk 14.0.1, so above output shows those . if you're using Java 13, & if you want to use long command-set shown above then run this nano command after that: nano ~/TestJava.sh , & change the line which has version number 14.0, into 13.0 , if you want to use a shorter command which is also shown in above, then (also for this) just change the 14.0 into 13.0)
  • Done . From this point-on, you will-not/should-not see any-other blocks/locks from macOS for using/running that java.

OPTIONAL STEP : if you want-to then before running a java-based App, either setup the JAVA_HOME env var globally (to apply same Java on all java-based apps), or Use a shell-script to setup a specific Java to run a specific App . A sample of such shell script is shown in above long command-set . if you want-to then follow this(goto bottom-side "Optional : Java ENV VAR" section) or this or any other better instructions.

OPTIONAL STEP : you can see all installed Java versions with: /usr/libexec/java_home -V
(you should see your installed version on the displayed list)

mentioning "General"-tab under "Security & Privacy. Moving Env Var setup related option/instruction in above
Source Link
atErik
  • 201
  • 2
  • 8
  • in macOS-X Catalina (or macOS-XI/11/X1 after it), obtain the "openjdk*.tar.gz" archive-file (not dmg/zip) from OpenJDK.Java.net or its archive-site, (make sure you see "https" (or Locked-Lock-symbol) in web-browser when you download). Then verify/compare downloaded file's authenticity/integrity, you may use hash/digest SHA256 code shown on openjdk site, Use openssl tool in Terminal utility : with such command: openssl sha256 & then drag the openjdk*.tar.gz file from Finder into that openssl command-line in Terminal, press enter to compute hash/digest, then Compare computed digest with what is shown on https://OpenJDK.Java.net/ secure webpage,
  • double-click on it (to decompress it) in Finder , MacOS may show notice & stop that,
  • Open your "System-Preferences" > "Security & Privacy" > under "General" tab > goto bottomside section "Allow Apps Downloaded From" > press the "Allow" or "Open anyway" button there to allow the decompression of "openjdk*.tar.gz" archive-file (macOS may/will ask to enter Password of a privileged Admin type account), then it should decompress , if it does not then again double tap on the "openjdk*.tar.gz" in Finder, & choose "Open"/"Allow" button if macOS asks you again , then it will finally decompress that "*.tar.gz" file,
  • copy the new OpenJDK folder "jdk*.jdk" , & goto below destination folder & move (to move use "alt/option" button: the "paste" will change into "move") the "jdk*.jdk" folder inside this destination location:
    "/Library/Java/JavaVirtualMachines/"
    macOS will ask again to enter a privileged accnt Password, do that to complete the move.
  • open Terminal , run this command: /usr/libexec/java_home
    if output contains+shows : "/Library/Java/JavaVirtualMachines/jdk-*.jdk/Contents/Home" , where * will actually show your installed Java version number, then its good.
  • in Terminal, run this long command-set:   
    echo '#!/bin/bash' > ~/TestJava.sh ; echo "export JAVA_HOME=\"\$(/usr/libexec/java_home --version 14.0)\";" >> ~/TestJava.sh ; echo "export PATH=\"\$JAVA_HOME/bin:\$PATH\";" >> ~/TestJava.sh ; echo "java -version ;" >> ~/TestJava.sh ; chmod +x ~/TestJava.sh ; ~/TestJava.sh
    if you want to avoid above long command-set, then run this shorter command:   
    $($(/usr/libexec/java_home --version 14.0)/bin/java -version)
    macOS will ask you to enter a privileged accnt + Password again, do that, & choose "Open"/"Allow", then you should see output like this:
    openjdk 14.0.1 2020-04-14
    OpenJDK Runtime Environment (build 14.0.1+7)
    OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
    (at the time of writing this answer i used openjdk 14.0.1, so above output shows those . if you're using Java 13, & if you want to use long command-set shown above then run this nano command after that: nano ~/TestJava.sh & change the line which has version number 14.0, into 13.0 , if you want to use a shorter command which is also shown in above, then (also for this) just change the "14.0" into "13.0")
  • Done . From this point-on, you will-not/should-not see any-other blocks/locks from macOS for using/running that java  . If you want-to then before running a java-based App, either setup the JAVA_HOME env var globally, or Use a shell-script to setup a specific Java to run a specific App.

OPTIONAL STEP : you can see all installed Java versions with: /usr/libexec/java_home -V

OPTIONAL STEP : if you want-to then before running a java-based App, in macOS (Catalina or after it)either setup the JAVA_HOME env var, either globally/system, or Use a shell-wide Or specifically forscript to setup a single appspecific Java to run a specific App (before running it),. A sample of such shell script is shown in above long command-set . if you want-to then follow this(goto bottom-side "Optional : Java ENV VAR" section) or this or any other better instructions.

OPTIONAL STEP : you can see all installed Java versions with: /usr/libexec/java_home -V

  • in macOS-X Catalina (or macOS-XI/11/X1 after it), obtain the "openjdk*.tar.gz" archive-file (not dmg/zip) from OpenJDK.Java.net or its archive-site, (make sure you see "https" (or Locked-Lock-symbol) in web-browser when you download). Then verify/compare downloaded file's authenticity/integrity, you may use hash/digest SHA256 code shown on openjdk site, Use openssl tool in Terminal utility : with such command: openssl sha256 & then drag the openjdk*.tar.gz file from Finder into that openssl command-line in Terminal, press enter to compute hash/digest, then Compare computed digest with what is shown on https://OpenJDK.Java.net/ secure webpage,
  • double-click on it (to decompress it) in Finder , MacOS may show notice & stop that,
  • Open your "System-Preferences" > "Security & Privacy" > under "General" tab > goto bottomside section "Allow Apps Downloaded From" > press the "Allow" or "Open anyway" button there to allow the decompression of "openjdk*.tar.gz" archive-file (macOS may/will ask to enter Password of a privileged Admin type account), then it should decompress , if it does not then again double tap on the "openjdk*.tar.gz" in Finder, & choose "Open"/"Allow" button if macOS asks you again , then it will finally decompress that "*.tar.gz" file,
  • copy the new OpenJDK folder "jdk*.jdk" , & goto below destination folder & move (to move use "alt/option" button: the "paste" will change into "move") the "jdk*.jdk" folder inside this destination location:
    "/Library/Java/JavaVirtualMachines/"
    macOS will ask again to enter a privileged accnt Password, do that to complete the move.
  • open Terminal , run this command: /usr/libexec/java_home
    if output contains+shows : "/Library/Java/JavaVirtualMachines/jdk-*.jdk/Contents/Home" , where * will actually show your installed Java version number, then its good.
  • in Terminal, run this long command-set:  echo '#!/bin/bash' > ~/TestJava.sh ; echo "export JAVA_HOME=\"\$(/usr/libexec/java_home --version 14.0)\";" >> ~/TestJava.sh ; echo "export PATH=\"\$JAVA_HOME/bin:\$PATH\";" >> ~/TestJava.sh ; echo "java -version ;" >> ~/TestJava.sh ; chmod +x ~/TestJava.sh ; ~/TestJava.sh
    if you want to avoid above long command-set, then run this shorter command:  $($(/usr/libexec/java_home --version 14.0)/bin/java -version)
    macOS will ask you to enter a privileged accnt + Password again, do that, & choose "Open"/"Allow", then you should see output like this:
    openjdk 14.0.1 2020-04-14
    OpenJDK Runtime Environment (build 14.0.1+7)
    OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
    (at the time of writing this answer i used openjdk 14.0.1, so above output shows those . if you're using Java 13, & if you want to use long command-set shown above then run this nano command after that: nano ~/TestJava.sh & change the line which has version number 14.0, into 13.0 , if you want to use a shorter command which is also shown in above, then (also for this) just change the "14.0" into "13.0")
  • Done . From this point-on, you will-not/should-not see any-other blocks/locks from macOS for using/running that java  . If you want-to then before running a java-based App, either setup the JAVA_HOME env var globally, or Use a shell-script to setup a specific Java to run a specific App.

OPTIONAL STEP : you can see all installed Java versions with: /usr/libexec/java_home -V

OPTIONAL STEP : if you want-to, in macOS (Catalina or after it) setup the JAVA_HOME env var, either globally/system-wide Or specifically for a single app (before running it), follow this(goto bottom-side "Optional : Java ENV VAR" section) or this or any other better instructions.

  • in macOS-X Catalina (or macOS-XI/11/X1 after it), obtain the "openjdk*.tar.gz" archive-file (not dmg/zip) from OpenJDK.Java.net or its archive-site, (make sure you see "https" (or Locked-Lock-symbol) in web-browser when you download). Then verify/compare downloaded file's authenticity/integrity, you may use hash/digest SHA256 code shown on openjdk site, Use openssl tool in Terminal utility : with such command: openssl sha256 & then drag the openjdk*.tar.gz file from Finder into that openssl command-line in Terminal, press enter to compute hash/digest, then Compare computed digest with what is shown on https://OpenJDK.Java.net/ secure webpage,
  • double-click on it (to decompress it) in Finder , MacOS may show notice & stop that,
  • Open your "System-Preferences" > "Security & Privacy" > under "General" tab > goto bottomside section "Allow Apps Downloaded From" > press the "Allow" or "Open anyway" button there to allow the decompression of "openjdk*.tar.gz" archive-file (macOS may/will ask to enter Password of a privileged Admin type account), then it should decompress , if it does not then again double tap on the "openjdk*.tar.gz" in Finder, & choose "Open"/"Allow" button if macOS asks you again , then it will finally decompress that "*.tar.gz" file,
  • copy the new OpenJDK folder "jdk*.jdk" , & goto below destination folder & move (to move use "alt/option" button: the "paste" will change into "move") the "jdk*.jdk" folder inside this destination location:
    "/Library/Java/JavaVirtualMachines/"
    macOS will ask again to enter a privileged accnt Password, do that to complete the move.
  • open Terminal , run this command: /usr/libexec/java_home
    if output contains+shows : "/Library/Java/JavaVirtualMachines/jdk-*.jdk/Contents/Home" , where * will actually show your installed Java version number, then its good.
  • in Terminal, run this long command-set: 
    echo '#!/bin/bash' > ~/TestJava.sh ; echo "export JAVA_HOME=\"\$(/usr/libexec/java_home --version 14.0)\";" >> ~/TestJava.sh ; echo "export PATH=\"\$JAVA_HOME/bin:\$PATH\";" >> ~/TestJava.sh ; echo "java -version ;" >> ~/TestJava.sh ; chmod +x ~/TestJava.sh ; ~/TestJava.sh
    if you want to avoid above long command-set, then run this shorter command: 
    $($(/usr/libexec/java_home --version 14.0)/bin/java -version)
    macOS will ask you to enter a privileged accnt + Password again, do that, & choose "Open"/"Allow", then you should see output like this:
    openjdk 14.0.1 2020-04-14
    OpenJDK Runtime Environment (build 14.0.1+7)
    OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
    (at the time of writing this answer i used openjdk 14.0.1, so above output shows those . if you're using Java 13, & if you want to use long command-set shown above then run this nano command after that: nano ~/TestJava.sh & change the line which has version number 14.0, into 13.0 , if you want to use a shorter command which is also shown in above, then (also for this) just change the "14.0" into "13.0")
  • Done . From this point-on, you will-not/should-not see any-other blocks/locks from macOS for using/running that java.

OPTIONAL STEP : if you want-to then before running a java-based App, either setup the JAVA_HOME env var globally, or Use a shell-script to setup a specific Java to run a specific App . A sample of such shell script is shown in above long command-set . if you want-to then follow this(goto bottom-side "Optional : Java ENV VAR" section) or this or any other better instructions.

OPTIONAL STEP : you can see all installed Java versions with: /usr/libexec/java_home -V

mentioning "General"-tab under "Security & Privacy"
Source Link
atErik
  • 201
  • 2
  • 8
Loading
adding a shorter version of the long command-set to test installed java
Source Link
atErik
  • 201
  • 2
  • 8
Loading
adding info on how to create a ~/TestJava.sh script to test any installed Java
Source Link
atErik
  • 201
  • 2
  • 8
Loading
link into a name-link/anchor does not work, StackExchage parser removes it, so removing that from here
Source Link
atErik
  • 201
  • 2
  • 8
Loading
modifying the link to goto specific paragraph of a specific answer
Source Link
atErik
  • 201
  • 2
  • 8
Loading
adding a link to setup JAVA_HOME env-var, etc
Source Link
atErik
  • 201
  • 2
  • 8
Loading
minor changes
Source Link
atErik
  • 201
  • 2
  • 8
Loading
corrected: decompressed folder starts with "jdk" not "openjdk"
Source Link
atErik
  • 201
  • 2
  • 8
Loading
minor correction
Source Link
atErik
  • 201
  • 2
  • 8
Loading
Source Link
atErik
  • 201
  • 2
  • 8
Loading