- How to Install Java on macOS
- Step 1 – Prerequisites
- Step 2 – Install JAVA on macOS
- Step 3 – Switching Between Java Version’s
- Conclusion
- How to install Java JDK on macOS
- 1. Homebrew install latest Java on macOS
- How To Install / Uninstall Multiple Java Versions In Mac OS By Home Brew Or Manually
- 1. Use HomeBrew To Install & Uninstall Java On Mac OS X.
- 1.1 Use HomeBrew Cask Command To Install Java JDK.
- 1.2 Use HomeBrew Cask Command To UnInstall JDK.
- 2. Install & Uninstall JDK In Mac OS Manually.
- 2.1 Install JDK Manually In Mac OS X.
- 2.2 Uninstall Java JDK Manually In Mac OS X.
- 3. Set JAVA_HOME & PATH System Environment Variable.
- 4. Question & Answer.
- 4.1 How to manage multiple JDK versions on mac OS X use SDKMAN .
- gwpantazes / How to Install JDK MacOS Homebrew.md
- This comment has been minimized.
- sespinosa commented Feb 21, 2020
- This comment has been minimized.
- gwpantazes commented Feb 24, 2020 •
- This comment has been minimized.
- sespinosa commented Feb 24, 2020
- This comment has been minimized.
- fazlizekiqi commented Apr 1, 2020
- This comment has been minimized.
- jiamo commented Apr 5, 2020 •
- This comment has been minimized.
- hardik-dadhich commented May 27, 2020
- This comment has been minimized.
- dedoussis commented Jun 1, 2020 •
- This comment has been minimized.
- hardik-dadhich commented Jun 1, 2020
- This comment has been minimized.
- gwpantazes commented Jun 2, 2020 •
How to Install Java on macOS
Java is a general-purpose, secure, robust, object-oriented language developed by Sun Microsystems in 1990. Java is portable which means it follows to write once run anywhere paradigm. Many of the useful application are build on Java and required Java runtime environment. If you are preparing your system for the developing new java applications, you need to install JDK on your machine.
The latest version is Java 15 which was released in September 15, 2020. This tutorial helps you to install Java on macOS system.
Step 1 – Prerequisites
Before starting the installation of Java using this tutorial you must have the following prerequisites
- Terminal: You must have Mac Terminal access and little knowledge about working with the terminal application. Ao login to your Mac system and open terminal
- Homebrew: This tutorial relies on Homebrew, So you must have homebrew installed. Homebrew can be installed with a single command.
Step 2 – Install JAVA on macOS
At the time of writing this tutorial the available version, Java 11 LTS and Java 15 latest for the installation.
- Tap adoptopenjdk/openjdk- Use the following commands to view the details about java versions to be install.
- Search Available JDK- View all the available Java versions to install
- Install Java – Use one of the following commands to install Java 8, 9, 10, 11, 12, 13, 14 and 15. Generally, we required Java 8, 11 LTS versions.
The installation process may take some time to complete depending on your network speed.
Check Version – Once the installation finished, verify the installed Java version.
Default latest installed version will be active on your machine.
Step 3 – Switching Between Java Version’s
You system may have installed multiple Java versions. For example, I have installed Java 8, 11 and 15 on my system. To view the installed Java version execute:
Create or edit the existing
/.bash_profile in your favorite text editor. Then export JAVA_HOME environment variable to specific java version, you want to use as default on Mac.
Save file and close it. The above settings will make JAVA_HOME point to JAVA 11.
Execute the following command to reload environment.
All done, check the current active java version
When you want to switch JDK version again, update the
/.bash_profile and export JAVA_HOME to other JDK version.
Conclusion
This tutorial explained you to how to install Java on macOS. Also provides you steps to switching between multiple installed Java versions.
You can visit Github page of the OpenJDK casks.
Источник
How to install Java JDK on macOS
By mkyong | Last updated: January 19, 2021
Viewed: 220,923 (+5,913 pv/w)
This article shows how to install Java JDK on macOS, Homebrew package manager, manual installation, and switch between different JDK versions.
- macOS 11 Big Sur
- Homebrew 2.7.4
- JDK 8, 14, 16, 16 (AdoptOpenJDK and OpenJDK)
P.S At the time of writing, the latest JDK GA is JDK 15, and the early access build is JDK 16.
Note
Since macOS 10.15 Catalina, the default Terminal shell switch from the bash (Bourne-again shell) to zsh (Z shell). And we should move all the startup scripts and environment variables in
1. Homebrew install latest Java on macOS
1.1 Install and upgrade Homebrew.
1.2 brew search java to find all available Java-related formula.
1.3 brew info to show the formula details.
The java formula is always containing the latest Java JDK (OpenJDK) GA version; at the time of writing, the latest GA is JDK 15.
The java11 formula is containing the Java 11 LTS version.
1.4 brew install java to install the latest JDK 15.
1.5 Where does Homebrew install the java?
Homebrew installed the JDK files and directories at /usr/local/Cellar/openjdk/ , and symbolic link at /usr/local/opt/openjdk points to the latest Java 15.0.1 version.
1.6 The java formula is keg-only, which means it is installed in /usr/local/Cellar but not linked into places like /usr/local/bin or /Library/Java/JavaVirtualMachines/ (macOS /usr/bin/java wrapper).
For macOS /usr/bin/java wrapper to find the installed JDK, we manually create a symbolic link at /Library/Java/JavaVirtualMachines/ .
Источник
How To Install / Uninstall Multiple Java Versions In Mac OS By Home Brew Or Manually
This article will tell you how to install/uninstall multiple java versions on mac os both use homebrew or manually. It also shows you how to set JAVA_HOME & PATH system environment variable to make your installed JDK as the default JDK. We recommend you to use homebrew because it provides a lot of easy-to-use tools.
1. Use HomeBrew To Install & Uninstall Java On Mac OS X.
1.1 Use HomeBrew Cask Command To Install Java JDK.
- Install HomeBrew on your mac os, please read the article How To Install HomeBrew On Mac OS.
- Run the below command to install the homebrew cask extension, cask extension tool can help you to install and manage software packages easily.
- Run brew search java or brew search jdk command to find your desired java or JDK version. Below is the search result for the command brew search java .
Below is the search result for the command brew search jdk .
Now install the JDK version that you need like below. During the installation process, you may encounter some error messages like Error: Cask ‘java8’ is unavailable: No Cask with this name exists or Error: Cask adoptopenjdk8 exists in multiple taps.
1.2 Use HomeBrew Cask Command To UnInstall JDK.
- Run homebrew cask command $ brew cask uninstall java to uninstall open JDK 12.0.1. If you want to uninstall open JDK 8 then run $ brew cask uninstall caskroom/versions/adoptopenjdk8 .
Below command uninstall open JDK 12.0.1.
Below command uninstall open JDK 8.
During the above JDK uninstall process, you may encounter the below error, Error: Cask adoptopenjdk8 exists in multiple taps. This is because you should uninstall caskroom/versions/adoptopenjdk8 instead of adoptopenjdk8.
2. Install & Uninstall JDK In Mac OS Manually.
2.1 Install JDK Manually In Mac OS X.
- Download related JDK from oracle JDK download page. You should have an oracle account to log in before the download start.
- Double click the downloaded dmg file to install JDK, just follow the wizard to install it.
- When the installation complete, you can find the JDK install directory in folder /Library/Java/JavaVirtualMachines/. From the below output, we can see there are three JDK that has been installed, one ( adoptopenjdk-8.jdk ) is installed with homebrew, the other two ( jdk-12.0.1.jdk, jdk1.8.0_211.jdk ) are installed by download installation file from oracle.
2.2 Uninstall Java JDK Manually In Mac OS X.
Follow oracle’s documents, to manually uninstall installed JDK in mac os x, you just need to remove some files with root permission in the terminal like below.
-
- Open a terminal and run the below command to remove the java JDK installed directory.
- Run the below command to remove the java control panel if exist.
- Remove java applet plugins.
- Remove java application support.
- Remove the java updater list.
-
- Remove the java helper tool.
3. Set JAVA_HOME & PATH System Environment Variable.
Now we have known how to install/uninstall multiple java JDK versions on mac os. But after that, you need to set JAVA_HOME & PATH environment variable value to set your installed JDK as default JDK. So that you can use it easily.
- Run the below command in a terminal to go to the user home directory.
- Run $ vim .bash_profile command to open .bash_profile file to edit.
- Press esc then press i to enter insert mode and insert the below export command in .bash_profile file.
- Press esc then :wq! to save the above changes and quit the vim editor.
- Run $ source .bash_profile command to make the above changes take effect.
- Now run $ java -version , you can see the new JDK version is used by output info.
4. Question & Answer.
4.1 How to manage multiple JDK versions on mac OS X use SDKMAN .
- My macOS is Catalina Version 10.15.7, and I run the command /usr/libexec/java_home -verbose to find all the installed JDK versions. I installed JDK 12.0.1 and OpenJDK 1.8.0.
Now I want to install and manage more other JDK versions in it, how to manage the multiple JDK versions, thanks.
You can switch to use one JDK with the command $ sdk use java java-identifier .
Источник
gwpantazes / How to Install JDK MacOS Homebrew.md
How To Install Different JDK Versions on MacOS with Homebrew
Keywords: Java, JDK (Java Development Kit), MacOS, Homebrew, Specific Version
This how-to guide covers how to install different versions of the JDK on MacOS with Homebrew.
Table of Contents
This Guide Favors OpenJDK
This guide favors OpenJDK.
This guide favors free, simple, and permissive licensing whenever possible, so we will favor OpenJDK first, then AdoptOpenJDK if plain OpenJDK isn’t available, any other open source distributions, and finally Oracle JDK if no other options are available. We favor OpenJDK because it has a permissive license, the GPL v2 with Classpath Exception (aka linking exception). For more information, see Oracle now requires a subscription to use Java SE (2018).
- For Java 8 and later, OpenJDK is readily available.
- For versions prior to Java 8 or other special circumstances, OpenJDK may not be available. We will cover how to install whatever is most readily available.
About Command Line Outputs
Note that this guide contains plenty of CLI command outputs. The intent of including these outputs is to illustrate what output should look like. Our goal IS NOT to keep up with exactly what the output is at the present day. This guide DOES NOT guarantee or even attempt to keep all those command outputs updated with the ever-evolving Hombrew formulae changes.
What’s important are the commands, and the general form of the outputs. This guide WILL attempt to keep up-to-date with the best commands to run.
Just be aware that if something’s been working for a while, the command output might look old, but the command itself will probably still run fine for more recent updates.
Remember to frequently brew update . Homebrew may also auto-update upon running key homebrew commands such as install or upgrade .
Double check your registered taps by running brew tap . It’s generally good practice to have homebrew/cask and homebrew/cask-versions taprooms tapped, especially when installing multiple Java versions.
Check your taps.
If homebrew/cask and homebrew/cask-versions aren’t in the list of your registered taps, then run brew tap homebrew/cask and brew tap homebrew/cask-versions to tap them.
Tap into the cask caskroom.
Tap into the cask-versions caskroom.
Getting an Overview: How to Search Homebrew for Java formulae
A lot of the information in this how-to guide is simply gathered from brew search and brew info . If you’re still getting the hang of things, I highly recommend you run these commands yourself to get an overview of what’s available and learn how to search Homebrew’s formulae.
Java/JDK formula/cask names typically contain either java or jdk . Let’s brew search for java and jdk to see potential formulas.
We can see some of the formulae/casks we’re looking for, such as java , java11 , or java-beta .
We can see some more potential formulae/casks we’re looking for, such as openjdk , adoptopenjdk8 , and oracle-jdk .
Get the summary and metadata for a formula/cask you are interested in by running brew info
This comment has been minimized.
Copy link Quote reply
sespinosa commented Feb 21, 2020
You are a legend
This comment has been minimized.
Copy link Quote reply
gwpantazes commented Feb 24, 2020 •
Thanks @envs, I’ve incorporated your changes into a rewrite.
Honestly, using homebrew to install Java (especially OpenJDK) has gotten quite a bit easier than it used to be, so updating this seemed a bit silly 😛 since most people will intuitively install whatever they need with no trouble.
This comment has been minimized.
Copy link Quote reply
sespinosa commented Feb 24, 2020
@gwpantazes believe me, it´s not silly at all, even if it´s something that can be considered trivial, you need to know how to do it, is not intuitive so your help is greatly appreciated.
This comment has been minimized.
Copy link Quote reply
fazlizekiqi commented Apr 1, 2020
Does brew already have the newest openjdk?
I am getting only the openjdk 13 when searching for java.
This comment has been minimized.
Copy link Quote reply
jiamo commented Apr 5, 2020 •
How about install special version java such as 1.8.0_40?
This comment has been minimized.
Copy link Quote reply
hardik-dadhich commented May 27, 2020
How can I install java 1.8.0_192, I already have 1.8.0_212 in my mac. Help please
This comment has been minimized.
Copy link Quote reply
dedoussis commented Jun 1, 2020 •
brew caskinfo adoptopenjdk8 should be corrected to brew cask info adoptopenjdk8
This comment has been minimized.
Copy link Quote reply
hardik-dadhich commented Jun 1, 2020
but still how to download minor version 1.8.0_192
This comment has been minimized.
Copy link Quote reply
gwpantazes commented Jun 2, 2020 •
@fazlizekiqi Homebrew’s java points to the most recent stable OpenJDK (not Oracle!), so it will probably update to Java 14 in September 2020.
Oracle releases JDK feature release updates first, and typically OpenJDK takes 6 months to catch up and release the same JDK under the OpenJDK organization/license. Refer to Java Version History on Wikipedia to get an overview of this pattern: you can see in the release history table that Oracle’s Java SE 14 was released in March 2020, but OpenJDK’s release of the same JDK 14 will be ready 6 months later in September 2020. We must take into account these months of lag for OpenJDK to catch up, and we can expect to see Homebrew’s java refer to JDK 14 around September 2020 whenever OpenJDK puts up JDK 14. Until then, Homebrew’s java will refer to 13.
@dedoussis I have fixed this typo. Thanks for pointing it out.
brew caskinfo adoptopenjdk8 should be corrected to brew cask info adoptopenjdk8
To @jiamo and @hardik-dadhich, while I am not sure why you want older versions of Java, I will still look into how to get and work with multiple specific Java versions and try to see if I can help you with this.
- Just note that you should probably be using the most recent minor version of whatever JDK you are using unless you are specifically choosing to debug for the older JDK. If you don’t have a good reason to be targeting the older JDK, you should update to the newest minor version to get the latest bug and security fixes.
- OpenJDK’s archive warning says it rather clearly, so I will quote them:
WARNING: These older versions of the JDK are provided to help developers debug issues in older systems. They are not updated with the latest security patches and are not recommended for use in production.
I hope this is helpful in the meantime, before I figure out where to put this information either in this document or in another document. If you find a good way to handle this, even if it’s not perfect, or if my suggestion in this comment worked for your needs, please comment here. We can iteratively improve the document based on what you find.
Источник