How do I install Java on Mac OSX allowing version switching

0 votes

Because OpenJDK Java is a newer release, I want to install it on Mac OSX and have it work alongside other JDKs. Currently, I downloaded the tar.gz and placed it in my path, but this is difficult to maintain.

The only other install I found that does more things automatically is the one via Homebrew cask. It appears that only the current version is available:

brew cask info java
Jan 2, 2023 in DevOps on Cloud by Damonlang
• 1,230 points
561 views

1 answer to this question.

0 votes

With Homebrew and Jenv:

Assumption: You have a Mac and have already installed homebrew.

Install Java from the Oracle website. JDK can be installed in multiple versions. It will be installed in the following location:

 /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/
 /Library/Java/JavaVirtualMachines/jdk1.11.0_2.jdk/
 /Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/

Without jenv, the system will use the most recently installed java.

You can use jenv: if you want to use/manage multiple versions.

Install and set up jenv:

$ brew install jenv
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(jenv init -)"' >> ~/.zshrc
$ source ~/.zshrc

Add the installed java to jenv:

$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
$ jenv add /Library/Java/JavaVirtualMachines/14.0.2.jdk/Contents/Home

To see all the installed java:

$ jenv versions

Above command will give the list of installed java:

  system
  1.8
* 1.8.0.291 (set by /Users/lpatel/.jenv/version)
  14
  14.0
  14.0.2
  oracle64-1.8.0.291
  oracle64-14.0.2

Configure the java version which you want to use:

$ jenv global 1.8.0.291
answered Jan 3, 2023 by David
• 220 points

Related Questions In DevOps on Cloud

+2 votes
3 answers

How do I deploy Scala PlayFramework Project to IBM Bluemix

It seems that they are more than ...READ MORE

answered Oct 18, 2018 in DevOps on Cloud by lina
• 8,220 points
1,144 views
0 votes
1 answer

How do I include custom data in a AWS Cloudwatch Alert?

Since the web service uses the "event ...READ MORE

answered Aug 21, 2018 in DevOps on Cloud by Damon Salvatore
• 5,980 points
727 views
0 votes
0 answers

How do I change timezone in a docker container?

I'm running a docker container from docker-hub ...READ MORE

Jan 5, 2023 in DevOps on Cloud by Damonlang
• 1,230 points
755 views
0 votes
1 answer

How can I remove a port from url for node app using nginx

If you run your node server on ...READ MORE

answered Apr 10, 2018 in DevOps on Cloud by ajs3033
• 7,300 points
3,942 views
0 votes
1 answer

how to safely deploy npm install without it causing inconsistencies?

The recent versions on npm generates a ...READ MORE

answered Apr 11, 2018 in DevOps on Cloud by DareDev
• 6,890 points
943 views
+5 votes
7 answers

Docker swarm vs kubernetes

Swarm is easy handling while kn8 is ...READ MORE

answered Aug 27, 2018 in Docker by Mahesh Ajmeria
3,797 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,950 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP