In this article we will explorer how to install and manage multiple Java version on MacOS. For this purpose, we will use a well known Java Version Manager software called jEnv.
There are two Java releases
Feature | Oracle JDK | Open JDK |
Licensing | Commercial: Oracle Binary Code License Agreement | Open source: GNU GPL v 2 |
Release Cycle | Every three years (LTS) | Every three months |
Other Features | Flight Recorder Java Mission Control Application Class-Data Sharing Better Garbage Collection | Font Renderer |
Contributors | Oracle | Oracle Red Hat Azul Systems IBM Apple Inc. SAP AG |
We will use Homebrew (the package manager for MacOS) to install the required softwares, open a terminal and run following command to install homebrew on your Mac.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Optional: Remove Existing Java
If you have any existing version of java installed on your machine, open terminal run following commands on you Mac.
sudo rm -rf /Library/Java/*
sudo rm -rf /Library/PreferencePanes/Java*
sudo rm -rf /Library/Internet\ Plug-Ins/Java*
We will make use of Homebrew Cask (homebrew package to install GUI based applications), cask package is included by default in latest versions of homebew so we not need to install it separately.
Install Java version manager: jEnv
jEnv, a well known Java Version Manager is a command line tool to manage multiple versions of java on your machine, behind the scenes it uses JAVA_HOME
environment variable to do this.
Open a terminal window and run following command to install jEnv on your Mac machine.
brew install jenv
Output of successful installation will be as following.
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
==> Updated Casks
brave-browser
==> Downloading https://github.com/jenv/jenv/archive/0.5.4.tar.gz
==> Downloading from https://codeload.github.com/jenv/jenv/tar.gz/0.5.4
######################################################################## 100.0%
==> Caveats
To activate jenv, add the following to your ~/.profile:
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
==> Summary
🍺 /usr/local/Cellar/jenv/0.5.4: 82 files, 72.1KB, built in 2 seconds
Now we have jEnv installed on our machine and will add following entries to shell configuration
. Location and name of the shell configuration may vary depending on the currently active shell on your Mac. If you look at the output from last section it actually has the reference to the target shell configuration file i,e. ~/.profile
. So let’s open it with nano
text editor.
sudo nano ~/.zshrc
Add following entries in ~/.zshrc
file, save and exit the editor using Ctrl + O
then ENTER
and Ctrl + X
then ENTER
key combination. On older versions of MacOS, replace .zshrc
with .profile
.
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
jenv enable-plugin export
jenv enable-plugin maven
Now either restart the Terminal or type following command to reload the shell configurations.
source ~/.zshrc
Verify the installation of jEnv by running following command.
jenv doctor
Successful installation will produce output like following.
OK] No JAVA_HOME set
[ERROR] Java binary in path is not in the jenv shims.
[ERROR] Please check your path, or try using /path/to/java/home is not a valid path to java installation.
PATH : /usr/local/Cellar/jenv/0.5.4/libexec/libexec:/Users/u1/.jenv/shims:/Users/sma/.jenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
[OK] Jenv is correctly loaded
We will activate AdoptOpenJDK tap to install specific version of Open JDK, to do this from terminal run following command.
brew tap AdoptOpenJDK/openjdk
Now let’s start with installing Java 8. Please note that on older versions of MacOS following command will revsied as “brew cask install adoptopenjdk8
“.
brew install --cask adoptopenjdk8
Next install Open JDK version 11 using following command.
brew install --cask adoptopenjdk11
For successful installation the output will be something like following.
Updating Homebrew...
==> Downloading https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/down
Already downloaded: /Users/sma/Library/Caches/Homebrew/downloads/1d0d41e7cf8f14ebb4df0ff39fa16e0fe2a1ac85f05ae404c62841c6ff01d4c8--OpenJDK11U-jdk_x64_mac_hotspot_11.0.8_10.pkg
==> Verifying SHA-256 checksum for Cask 'adoptopenjdk11'.
==> Installing Cask adoptopenjdk11
==> Running installer for adoptopenjdk11; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are i
installer: Package name is AdoptOpenJDK
installer: Upgrading at base path /
installer: The upgrade was successful.
package-id: net.adoptopenjdk.11.jdk
version: 11.0.8+10
volume: /
location: Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk
install-time: 1602892594
🍺 adoptopenjdk11 was successfully installed!
Let’s also install the latest available version of java using following command.
brew install --cask adoptopenjdk
Configure JDK version with jEnv
Now we have Java 8, 11 and 16 (latest available version on publish date of this article) installed on our machine.
In this section will learn to configure current JDK version with the help of jEnv.
To enable jEnv switch between different java versions, we need to tel jEnv about all versions installed on our machine. Tun following command to get a list of all versions of java installed on your machine.
/usr/libexec/java_home -V
This will return list of all installed java versions as following.
Matching Java Virtual Machines (3):
16 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 16" /Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home
11.0.11 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 11" /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
1.8.0_292 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home
Now we will add each of the installed JDK to jEnv as following, please do remember to revise the commands according to path of versions installed on your machine.
jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home
jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
Let’s verify if all of the Java versions are now available to jEnv by running following command.
jenv versions
This will produce output like following.
* system (set by /Users/sma/.jenv/version)
1.8
1.8.0.292
11
11.0
11.0.11
16
openjdk64-1.8.0.292
openjdk64-11.0.11
openjdk64-16
Congratulations, you have setup jEnv successfully and can use it to manage your development environments easily.
Set global Java using jEnv
We can use following command to set global / system wide java version.
jenv global 16
Above command will set Java 15 as the system wide Java version, let’s verify it by running java -version command as following.
java -version
Following output confirms current java version as Java 15.
openjdk version "16" 2021-03-16
OpenJDK Runtime Environment AdoptOpenJDK (build 16+36)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 16+36, mixed mode, sharing)
Let’s switch our global version to Java 8 by running following command.
jenv global 1.8
Let’s confirm the change by running following command.
java -version
And output confirms that now the global java version is Java 1.8.
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.292-b10, mixed mode)
Set local Java using jEnv
Use following command to set project specific Java version, this will create a file named .java-version
and you can even commit this file in source control to share it with team.
jenv local 16
Set Shell specific Java using jEnv
We can set Java version for currently opened shell using following command.
jenv shell 11
109 thoughts on “How to manage multiple Java versions on MacOS”
Leave a Reply
You must be logged in to post a comment.
If you want to use the photo it would also be good to check with the artist beforehand in case it is subject to copyright. Best wishes. Aaren Reggis Sela
Tekken, Mortal Kombat, MMA. codes and free ps plus codes. Lorinda Schuyler Lorsung
At least most of the restructuring of the other garden was completed last year. Amil Skye Calla
But wanna ademit that this is extremely helpful, Thanks for taking your time to write this. Rebecka Reginauld Golden
I am truly grateful to the owner of this web page who has shared this wonderful piece of writing at at this place. Constanta Booth Tressa
Awesome! Its really remarkabke piece of writing, I have got much clerar idea concerning from this piece off writing. Nixie Rick Henka
Hi mates, pleasant paragraph and fastidious arguments commented at this place, I am in fact enjoying by these. Rhonda Tobin Elfont
That is a good tip especially to those fresh to the blogosphere. Felice Hernando Sawtelle
Excellent article. I am dealing with some of these issues as well.. Fionna Hewie Nanete
I was reading some of your posts on this website and I believe this site is really instructive! Keep posting . Raquel Jamal Samau
I really like and appreciate your article post. Awesome. Kippy Haily Torrell
Great work! That is the type of information that are supposed to be shared across the internet. Robin Tobias Ivers
If you want to obtain a great deal from this paragraph then you have to apply these techniques to your won webpage. Elianore Royall Gorlicki
Touche. Great arguments. Keep up the great spirit.
What a information of un-ambiguity and preserveness of valuable knowledge regarding unexpected emotions. Kaela Findlay Obelia
No matter if some one searches for his essential thing, thus he/she wishes to be available that in detail, thus that thing is maintained over here. Barbe Renault Winfrid
I really like and appreciate your blog article. Want more. Page Derek Zalucki
Great job Kimby. But then I did not expect anything but the best from you. Charlotte Padriac Lorraine
This post provides clear idea for the new viewers of blogging, that genuinely how to do blogging. Eartha Lane Blair
I have read so many articles on the topic of the blogger lovers but this post is truly a nice post, keep it up.
Hi there, I want to subscribe for this weblog to take newest updates, so where can i do it please help out.
I think you have noted some very interesting details, thanks for the post. Livvyy Kenon Chak
If you wish for to obtain a good deal from this paragraph then you have to apply such methods to your won webpage. Gisele Fidel Squier
Useful information. Lucky me I found your site by accident, and I am shocked why this accident did not came about earlier! I bookmarked it. Kalila Gearard Strickler
This article provides clear idea designed for the new viewers of blogging, that really how to do blogging and site-building. Katheryn Mathias Einberger
This is a very basic pass and must be second nature to a great soccer player. Sidonia Allan Broek
Outstanding post, I conceive people should acquire a lot from this weblog its real user friendly. So much fantastic information on here . Tamqrah Napoleon Ruzich
The choices that you make can make or break the success of your blog. Josepha Trent Kawai
I visited multiple blogs however the audio feaature for audio songs current at this site is rewlly superb. Claude Carl Dulci
Hi Dear, are you truly visiting this site regularly, if so afterward you will definitely get nice knowledge. Madalena Luigi Reeve
I think the admin of this web page is truly working hard in favor of his website, as here every material is quality based data. Pauletta Hector Sayer
We do not sell airline tickets, but help to find the cheapest. Is free. Ora Jamaal Bainbrudge
Very nice layout and great subject material , very little else we want : D. Denna Cazzie Sathrum
Please take a look at the web-sites we adhere to, such as this a single, as it represents our picks in the web. Vicky Wallie Ricardo
This article is truly a fastidious one it helps new internet viewers, who are wishing for blogging. Theresa Bendicty Eberly
Mi dui, tincidunt id venenatis vel, luctus quis lorem. Curabitur a ante non leo eleifend pretium. Vivamus efficitur ex varius dignissim imperdiet. Ethelind Lesley Gherlein
Towering genius distains a beaten path. It seeks regions hitherto unexplored. Petronille Giorgio Geraint
What a stuff of un-ambiguity and preserveness of valuable know-how about unpredicted feelings. Farica Kennedy Iong
Great delivery. Great arguments. Keep up the great work. Cyb Waiter Abagael
I do consider all the concepts you have presented on your post. Theo Kalil Halimeda
I have recently started a website, the info you offer on this site has helped me greatly. Thank you for all of your time & work. Molly Saw Arnoldo
You are my breathing in, I own few web logs and infrequently run out from to post . Olwen Dill Babbie
Way cool! Some extremely valid points! I appreciate you penning this post and also the rest of the site is very good. Josie Hillary Huskey
Excellent article! We are linking to this particularly great article on our website. Keep up the good writing. Adiana Nathanial Baily
You made a number of good points there. I did a search on the subject matter and found mainly folks will consent with your blog. Norry Donovan Tabib
I needed to thank you for this wonderful read!! I definitely loved every little bit of it. Siusan Natale Roede
I really liked your article. Thanks Again. Really Great. Rora Spenser Shaefer
I will immediately grab your rss feed as I can not in finding your e-mail subscription link or newsletter service. Marylee Sam Roye
Whats up very nice website!! Man .. Excellent .. Wonderful .. Janaye Oby Donal
I cannot thank you enough for the blog post. Really thank you! Awesome. Edin Travis Koenraad
I truly appreciate this article. Really thank you! Much obliged. Fiann Nappie Gagne
Article writing is also a excitement, if you be acquainted with afterward you can write otherwise it is complex to write. Shoshana Mortie Nevlin
Wonderful bike, solid brakes and also comfy riding placement. Priscella Aristotle Carlton
Utterly composed content , appreciate it for entropy. Corri Archie Bravin
Im obliged for the article post. Really thank you! Fantastic. Candis Henrik Art
The best and clear News is very much imptortant to us. Bess Harry Amii
I just like the helpful info you supply to your articles. I will bookmark your blog and take a look at once more here regularly. Trudie Raleigh Tiffanle
Excellent, what a website it is! This webpage provides valuable information to us, keep it up. Beverly Dame Gaillard
Well I definitely liked reading it. This tip procured by you is very helpful for good planning. Glenda Elroy Magdalene
There is definately a lot to know about this subject. I really like all the points you made. Hedvig Jarrod Koblick
Rick and I will definitely be praying for you tomorrow. Dionis Abbe Durman
Hello. This post was really remarkable, particularly because I was investigating for thoughts on this issue last Saturday. Mariquilla Forster Griffin
I like the valuable info you provide to your articles. Melli Aloysius Usanis
Yes! Finally someone writes about buy skratch labs uk. Gray Humfrid Natividad
Thanks for the auspicious writeup. It actually used to be a enjoyment account it. Becky Nathaniel Abdu
There is obviously a lot to realize about this. I consider you made certain nice points in features also. Misti Edgardo Om
Thank you so much for sharing a great information. I appreciate your time and effort in your work. Keep posting. Marga Germayne Wahlstrom
Amazing things here. I am very happy to peer your article. Hillary Derron Mungo
Muchos Gracias for your blog. Really looking forward to read more. Fantastic. Cathryn Sig Ballman
Whats up very cool website!! Guy .. Beautiful .. Wonderful .. Chad Mickey Johst
Learning to control the ball is essential to good game play. Cornie Averell Lukas
Howdy very nice site!! Guy .. Excellent .. Superb .. Jaime Kevan Tarrant
By ensuring the field is safe, you can help prevent unnecessary injuries. Florina Giff Luby
I am actually happy to read this webpage posts which consists of lots of helpful information, thanks for providing these kinds of data. Lauryn Vittorio Atalanti
As the admin oof this website is working, no question very shortly itt will be renowned, due tto its quality contents. Irita Gearard Olatha
Good post. I absolutely love this website. Continue the good work! Olly Dom Brindle
I am really loving the theme/design of your weblog. Do you ever run into any browser compatibility problems? A number of my blog visitors have complained about my blog not operating correctly in Explorer but looks great in Firefox. Do you have any recommendations to help fix this issue? Sherill Brnaba Homans
Great blog here! Also your site loads up fast! What web host are you using? Can I get your affiliate link to your host? I wish my web site loaded up as quickly as yours lol Patrica Horten Eal
There is visibly a bundle to identify about this. I suppose you made various good points in features also. Kelly Benedikt Ondine
An attention-grabbing discussion is price comment. I feel that you should write extra on this matter, it may not be a taboo topic however generally individuals are not sufficient to talk on such topics. To the next. Cheers Bea Wolfy Arlon
to discover his goal then the achievements will be Danielle Warde Florian
I learn something new and challenging on blogs I stumbleupon everyday. Corilla Alano Aidan
Everything is very open with a really clear description of the issues. It was truly informative. Your website is useful. Thank you for sharing! Ariana Tarrance Erving
Right away I am ready to do my breakfast, once having my breakfast coming yet again to read additional news.| Julienne Job Autry
This is such an informative article. I have been searching for out more concerning this subject and also stopping working. Thank benefits I determined to browse once again and discovered you. Congratulations on a superb message as well as I will certainly be reading a lot more. Anabelle Guntar Ranie
You ought to take part in a contest for one of the highest quality blogs on the internet. I will recommend this website! Blinny Davon Philipson
In its default setting, your Casino will highlight incoming messages on its lock screen. This is something that some find convenient, but others do not like so much. If you are one that does not like that feature, you will be happy to learn that you can stop that feature from continuing. Simply go to the Notifications section of your settings menu and choose messages. You can then turn off the Show Preview option. Cynthia Griffin Selima
I love reading an article that can make men and women think. Gweneth Emory Eudoca
Hey there! I just wish to offer you a huge thumbs up for the excellent information you have right here on this post. I will be returning to your web site for more soon. Anica Rutledge Cordula
There is certainly a great deal to find out about this topic. I like all the points you have made. Peggy Juan Rotberg
Usually I do not learn article on blogs, however I would like to say that this write-up very pressured me to check out and do it! Your writing style has been surprised me. Thanks, quite nice post. Halley Saxon Hillery
What a information of un-ambiguity and preserveness of valuable familiarity about unexpected emotions. Dorette Ethelbert Trilbie
Thanks , I have just been looking for information about this subject for ages and yours is the best I have found out so far. However, what about the bottom line? Are you sure concerning the source? Cindra Morton Pence
In the audience tonight with friends and family: loved it! What a great little script full of gut wrenching emotions at times but then with some just brilliant one-liner responses that guaranteed audience engagement! Kaitlin Bobbie Carmelina
I really like reading through a post that can make people think. Also, thanks for permitting me to comment! Ambur Courtney Scibert
big breasted young women
cams free
girl puberty video for 5th grade
Thanks to my father who stated to me on the topic of this webpage, this web site is really awesome. Cherice Bret Nazler
It’s awesome in support of me to have a site, which is beneficial in support of my experience.
thanks admin
I do not know whether it’s just me or if perhaps everybody else experiencing problems with your blog.
It seems like some of the written text in your content are running off the screen. Can someone else please
comment and let me know if this is happening to them too?
This could be a problem with my browser because I’ve had this happen before.
Kudos
I am regular visitor, how are you everybody? This piece of writing posted at this website is genuinely fastidious. Karlie Rem Barden
Thanks for sharing such a good opinion, piece of writing is pleasant,
thats why i have read it fully
Hey there! I’ve been following your weblog for a while now and finally got the bravery to go ahead
and give you a shout out from Kingwood Texas! Just wanted to mention keep
up the great work!
Hi there, just became alert to your blog through Google,
and found that it’s truly informative. I am gonna watch out for brussels.
I will appreciate if you continue this in future. A lot of people will be benefited from your writing.
Cheers!
Magnificent beat ! I wish to apprentice while you amend your web site, how can i subscribe
for a blog website? The account aided me a acceptable
deal. I had been a little bit acquainted of this your
broadcast offered bright clear idea
Very good info. Lucky me I discovered your blog by accident (stumbleupon).
I have book-marked it for later!
wonderful content, i love it
I am grateful to you for this beautiful content. I have included the content in my favorites list and will always wait for your new blog posts.