Installing Java on OSX using Homebrew

There was a time where I have installed all my applications by downloading it from the provider or a page I trust. Then I became familiar with Homebrew and decided to manage all my applications with this tool. As the first step, I need to uninstall Java, which is installed the old fashion way. How to uninstall Java is well documented on the Java’s help page. I have copied the relevant parts here. Open the terminal and copy the following commands:

sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane sudo rm -fr ~/Library/Application\ Support/Oracle/Java

This commands will remove your JRE to remove the JDK you need to run the following command:

sudo rm -fr /Library/Java/JavaVirtualMachines/jdk[version].jdk/

The next step is to add the cask repository if you don’t have it already:

brew tap caskroom/cask

Now you can install the latest java version if you don’t add a specific version number.

brew cask install java

Otherwise, you need to add the version number:

brew cask install java[version] // 6 and 8 supported

With the following command you can check which version is the latest one:

brew cask info java

To check the installation you can run one of the following commands:

/usr/libexec/java_home (environment variable)
java -version (JRE)
javac -version (JDK)
chevron_left
chevron_right

Leave a comment

Your email address will not be published. Required fields are marked *

Comment
Name
Email
Website

This site uses Akismet to reduce spam. Learn how your comment data is processed.