DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Java
  4. JDK and macOS

JDK and macOS

Having trouble defining your JDK runtime on macOS? Java and Macs, am I right? Here's one solution to get you up and running via Terminal.

Chris Luff user avatar by
Chris Luff
·
May. 17, 18 · Tutorial
Like (26)
Save
Tweet
Share
19.58K Views

Join the DZone community and get the full member experience.

Join For Free

This is going to be short. I mean really short. Not even any diversions.

I mentioned in a recent post how "cross" I get with advice on setting JAVA_HOME on macOS. It is just not that complicated. I have seen many questions on StackOverflow and other forums...

  • "How do I set JAVA_HOME on Mac?"
  • "Where is Java installed on OSX?"

If you don't get a petulant response from someone too big to be polite, you'll get a myriad of suggestions.

  • First rule; DON'T install anything other than the JDK, it's just not worth your while.
  • Secondly, DON'T be afraid of making changes — you won't break anything fundamental.

So, you've installed JDK10 from Oracle, the newest and shiniest. Now, no older Java-based solutions function. So what do we do?!

Lets set the operating system's JAVA_HOME. We do that in the bash_profile. If it does not exist, create it. It doesn't even matter how, the only requirement is that it is hidden and that it is in the root directory of your user.

So, how do we do that? Open a terminal (I like iTerm):

open ~/.bash_profile


I actually use Sublime Text myself, but whatever takes your fancy. If you do not have a bash_profile, then simply create one:

cat ~/.bash_profile


Now, which JDK(s) do you have installed? Again, it is not complicated:

/usr/libexec/java_home -V


You'll get an output similar to my own:

Image title

Now, let's check what JAVA_HOME is now:

java -version

Image title

1.8.0_171-b11 - whatever!!

Let's add a line to that bash_profile we created.

export JAVA_HOME=`/usr/libexec/java_home -v 10.0.1`


Notice that I got the version from the output of the "-V" command. Now, all we have to do is reinitialize the terminal.

source .bash_profile


From here on in, whenever an application runs Java, it is going to read JAVA_HOME, which is set by the bash_profile. To change it, you just follow the same process. I have been using this method of defining my runtime for some years.

I've not found a scenario where this solution does not cover the bases, but I am happy to hear stories.

Java (programming language) Java Development Kit MacOS

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Secrets Management
  • Deploying Java Serverless Functions as AWS Lambda
  • The Future of Cloud Engineering Evolves
  • Too Many Tools? Streamline Your Stack With AIOps

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: