$show=/label

How to install Java 8 on Mac? Installing Java 8 on Latest Mac OS X (HomeBrew Guide)

SHARE:

A new guide to install java 8 on Mac OS X today. Installation steps using homebrew, manual installation, and java version switching in a simple way.

1. Introduction


In this tutorial, You'll be learning how to install Java 8 or the latest versions of java in Mac OS.
If you have got the new mac book then you are existed to install java.

This is a very easy process and will show you step by step in an easy manner.

First, let us start with the Manual Installation and next go with the HomeBrew approach which is simpler managed automatically with few commands.

Before that download the latest java from Oracle or OpenJDK official websites.

Read more on Why Java is preferred?

How to install Java 8 on Mac? Installing Java 8 on Latest Mac OS X (HomeBrew Guide)


2. Manual Installation of java 8 or Higher Versions


Let us go through the manual installation of Java 14 or 8. To run the following you would need the admin access.

2.1 Download the latest JDK or needed version for you.

2.2 Copy the tar file to the location "/Library/Java/JavaVirtualMachines"
$ cd /Library/Java/JavaVirtualMachines

$ pwd
/Library/Java/JavaVirtualMachines

$ sudo cp ~/Downloads/openjdk-14_osx-x64_bin.tar.gz /Library/Java/JavaVirtualMachines

$ pwd
/Library/Java/JavaVirtualMachines

2.3 Extract the contents here.
$ sudo tar xzf openjdk-14_osx-x64_bin.tar.gz
2.4 Delete the tarfile if you no need to keep the backup.
$ sudo rm openjdk-14_osx-x64_bin.tar.gz
2.5 Find the java version installed
$ /usr/libexec/java_home -v14

/Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home
2.6 Add the java home path to the ".bash_profile" file.
open the file with the VI editor. Enter into edit mode by pressing 'i' and then add the below line. Press :wq to save and come out of VI editor.
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home
2.7 Source bash_priofile file
$ source ~/.bash_profile
2.8 Test the version installed on mac properly or not using "java --version".
$ java -version
openjdk version "14" 2020-03-17
OpenJDK Runtime Environment (build 14+36-1461)
OpenJDK 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home

3. Installing java 8 using HomeBrew

HomeBrew provides simpler way to install and manage the software and tools required on mac without any manual intervention.
If you are new then please see the article on HomeBrew installation and  Commands shown in the previous article.

3.1 Install Homebrew or update it if you have already on mac.
The update will take some time if you have done it a long time ago.

$ brew update
==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
################################################################################################################################################################ 100.0%
3.2 Add open jdk to the brew

By default, all repositories are not added to the brew. So, to add the additional repos you need to use the brew tap command.

$ brew tap adoptopenjdk/openjdk
Updating Homebrew...
3.3 Find all JDK versions are on Brew
$ brew search jdk
==> Formulae
openjdk                                                                           openjdk@11
==> Casks
adoptopenjdk                     adoptopenjdk12                   adoptopenjdk13-openj9            adoptopenjdk14-openj9-jre-large  adoptopenjdk9
adoptopenjdk10                   adoptopenjdk12-jre               adoptopenjdk13-openj9-jre        adoptopenjdk14-openj9-large      jdk-mission-control
adoptopenjdk11                   adoptopenjdk12-openj9            adoptopenjdk13-openj9-jre-large  adoptopenjdk8                    oracle-jdk
adoptopenjdk11-jre               adoptopenjdk12-openj9-jre        adoptopenjdk13-openj9-large      adoptopenjdk8-jre                oracle-jdk-javadoc
adoptopenjdk11-openj9            adoptopenjdk12-openj9-jre-large  adoptopenjdk14                   adoptopenjdk8-openj9             sapmachine-jdk
adoptopenjdk11-openj9-jre        adoptopenjdk12-openj9-large      adoptopenjdk14-jre               adoptopenjdk8-openj9-jre
adoptopenjdk11-openj9-jre-large  adoptopenjdk13                   adoptopenjdk14-openj9            adoptopenjdk8-openj9-jre-large
adoptopenjdk11-openj9-large      adoptopenjdk13-jre               adoptopenjdk14-openj9-jre        adoptopenjdk8-openj9-large
Venkateshs-MacBook-Pro-2:JavaVirtualMachines venkateshn$ 
It is showing with a blue tick for version 11. That means, My machine is already having the java 11 version.

3.4 Choose the right version and run one of the following commands.

brew cask install adoptopenjdk8
brew cask install adoptopenjdk9
brew cask install adoptopenjdk10
brew cask install adoptopenjdk11
brew cask install adoptopenjdk12
brew cask install adoptopenjdk13
brew cask install adoptopenjdk14

3.5 install JDK 14 version

This will take quite some time based on your internet speed.
$ brew cask install adoptopenjdk14
Updating Homebrew...
==> Downloading https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.1%2B7/OpenJDK14U-jdk_x64_mac_hotspot_14.0.1_7.pkg
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/233878254/64ac0f80-830e-11ea-8bcd-a9f8ee45c527?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'adoptopenjdk14'.
==> Installing Cask adoptopenjdk14
==> Running installer for adoptopenjdk14; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
Password:
installer: Package name is AdoptOpenJDK
installer: Upgrading at base path /
installer: The upgrade was successful.
package-id: net.adoptopenjdk.14.jdk
version: 14.0.1+7
volume: /
location: Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk
install-time: 1593938817
🍺  adoptopenjdk14 was successfully installed!
3.6 How to see the installed Java location?
Run from terminal "/usr/libexec/java_home -V" command which shows all java versions installed on this machine already.
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (6):
    14.0.1, x86_64: "AdoptOpenJDK 14" /Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home
    12.0.1, x86_64: "Java SE 12.0.1" /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home
    11.0.7, x86_64: "Java SE 11.0.7" /Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home
    1.8.0_252, x86_64: "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
    1.8.0_251, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home
    1.8.0_161, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home
3.7 Verify the java version
$ java --version
openjdk 11.0.7 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10)
OpenJDK 64-Bit Server VM (build 11.0.7+10, mixed mode)
Currently, I have set JAVA_HOME to java 11 version. Because of this, we are seeing the java 11 version even though installed the latest java 14.
That's all. The latest version is installed.

4. How to change or Switching between Java versions

In the above sections, We've already shown you how to install the different versions of java using HomeBrew and Manual installation steps.

If you have installed any version of java and there are some cases you need to change the java version based on your project needs.

Note: In the market, there is a tool jenv.be to switch between the java versions but I prefer to use Export JAVA_HOME in .bash_profile file.

4.1 First, let us see how to see the installed versions of java.

Open the terminal and hit the "/usr/libexec/java_home -V" command and this shows all versions installed with locations.
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (6):
    14.0.1, x86_64: "AdoptOpenJDK 14" /Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home
    12.0.1, x86_64: "Java SE 12.0.1" /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home
    11.0.7, x86_64: "Java SE 11.0.7" /Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home
    1.8.0_252, x86_64: "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
    1.8.0_251, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home
    1.8.0_161, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home
4.2 Open the .bash_profile file

$ vim ~/.bash_profile

Add the following to the .bash_profile file
export JAVA_HOME_8=$(/usr/libexec/java_home -v1.8)
export JAVA_HOME_11=$(/usr/libexec/java_home -v11)
export JAVA_HOME_14=$(/usr/libexec/java_home -v14)

# Java 8
export JAVA_HOME=$JAVA_HOME_8

# Java 11
# export JAVA_HOME=$JAVA_HOME_11
Save the file and come out of VI editor.

4.3 Based on the above change, we are setting JAVA_HOME to java 1.8 version.

4.4 Reload the .bash_profile
$ source ~/.bash_profile
4.5 Verify the java version
$ java -version

openjdk version "1.8.0_251"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_251-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.251-b08, mixed mode)

5. Conclusion

In this article, You have seen how to install Java on Mac OS with manual and HomeBrew Installation with step by step.

As well as seen how to change the java version as you needed from the terminal with few commands.



Ref

Oracle java 8 steps

Open JDK

HomeBrew Commands

jenv.be

How to change the Java version on Mac OS

COMMENTS

BLOGGER

About Us

Author: Venkatesh - I love to learn and share the technical stuff.
Name

accumulo,1,ActiveMQ,2,Adsense,1,API,37,ArrayList,16,Arrays,3,Bean Creation,3,Bean Scopes,1,BiConsumer,1,Blogger Tips,1,Books,1,C Programming,1,Collection,4,Collections,21,Collector,1,Command Line,1,Compile Errors,1,Configurations,7,Constants,1,Control Statements,8,Conversions,5,Core Java,74,Corona India,1,Create,2,CSS,1,Date,3,Date Time API,3,Dictionary,1,Difference,1,Download,1,Eclipse,2,Efficiently,1,Error,1,Errors,1,Exception,1,Exceptions,3,Fast,1,Files,9,Float,1,Font,1,For examples,1,For loop examples,1,For Loop in Java,1,Form,1,Freshers,1,Function,3,Functional Interface,2,Garbage Collector,1,Generics,4,Git,4,Grant,1,Grep,1,HashMap,1,HomeBrew,2,HTML,2,HttpClient,2,Immutable,1,Inner for loops,1,Installation,1,Interview Questions,5,Iterate,2,Jackson API,3,Java,29,Java 10,1,Java 11,5,Java 12,5,Java 13,2,Java 14,2,java 5 For loop,1,Java 8,52,Java 8 Difference,2,java 8 Stream Examples,1,Java 9,1,Java Conversions,12,Java Design Patterns,1,Java Files,1,Java for loop,1,Java Program,2,Java Programs,65,java.lang,5,java.util. function,1,jQuery,1,Kotlin,10,Kotlin Conversions,3,Kotlin Programs,6,Lambda,1,lang,29,Leap Year,1,live updates,1,Mac OS,2,Math,1,Maven,1,Method References,1,Mockito,1,MongoDB,3,Nested for loop,1,Nested for loop examples,1,New Features,1,Operations,1,Optional,4,Oracle,5,Oracle 18C,1,Partition,1,Patterns,1,Programs,1,Property,1,Python,2,Quarkus,1,Read,1,Real Time,1,Recursion,2,Remove,2,Rest API,1,Schedules,1,Serialization,1,Servlet,1,Sorting Techniques,8,Spring,2,Spring Boot,23,Spring Email,1,Spring MVC,1,Stream,3,Streams,13,String,57,String Programs,9,String Revese,1,Swing,1,System,1,Tags,1,Threads,9,Tomcat,1,Tomcat 8,1,Troubleshoot,16,Unix,2,Updates,3,util,5,While Loop,1,
ltr
item
JavaProgramTo.com: How to install Java 8 on Mac? Installing Java 8 on Latest Mac OS X (HomeBrew Guide)
How to install Java 8 on Mac? Installing Java 8 on Latest Mac OS X (HomeBrew Guide)
A new guide to install java 8 on Mac OS X today. Installation steps using homebrew, manual installation, and java version switching in a simple way.
https://1.bp.blogspot.com/-GRPs8PnB32M/XwG-vve1pJI/AAAAAAAACzc/h_qBfZFWVpo-n0vnOvbuGx6YuWXJUDDpQCLcBGAsYHQ/s640/How%2Bto%2Binstall%2BJava%2B8%2Bon%2BMac%253F%2BInstalling%2BJava%2B8%2Bon%2BLatest%2BMac%2BOS%2BX%2B%2528HomeBrew%2BGuide%2529.png
https://1.bp.blogspot.com/-GRPs8PnB32M/XwG-vve1pJI/AAAAAAAACzc/h_qBfZFWVpo-n0vnOvbuGx6YuWXJUDDpQCLcBGAsYHQ/s72-c/How%2Bto%2Binstall%2BJava%2B8%2Bon%2BMac%253F%2BInstalling%2BJava%2B8%2Bon%2BLatest%2BMac%2BOS%2BX%2B%2528HomeBrew%2BGuide%2529.png
JavaProgramTo.com
https://www.javaprogramto.com/2020/07/mac-install-java-8.html
https://www.javaprogramto.com/
https://www.javaprogramto.com/
https://www.javaprogramto.com/2020/07/mac-install-java-8.html
true
3124782013468838591
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content