Jump to content

(Java - Windows 10) Issue with environment variables?

I have JDK 17 and 1.8 installed. They say it's a requirement to set environment variables to use the JDK, but I realized earlier today I've been using both of those versions just fine while I only had environment variables set for a JDK 11 version that I uninstalled months ago.

 

Even without the variables set, running "java -version" in the command prompt shows that I have JDK 17 installed, but it won't show JDK 1.8. Even after I redownloaded 1.8 and set the variables for it, the command prompt still won't show 1.8.

 

This endeavor has only made me confused. What is the purpose of setting the environment variables? Are they necessary?

Java Trainee (Novice)

Thanks in advance~

Link to post
Share on other sites

Environment variables set the default version of Java. i.e. if you run `java` without any other arguments.

`java -version` will show the version set in the environment variable, usual java_home.

If you're using a build system (maven/gradle) you can set your target version to whatever.

Link to post
Share on other sites

A lot of software depends on JAVA_HOME to detect where Java is installed. However, depending on the OS you're using there are other ways to switch/detect the default Java version. For example, on Manjaro, I can do:

archlinux-java status

This will show me the JDKs/JREs I have installed. I can then use

sudo archlinux-java set java-13-openjdk

to set the one I want to be the default. The default is simply the one that is linked below "/usr/lib/jvm/default", which is also what $JAVA_HOME points to for backwards compatibility.

 

In other words, you should mention the OS you're using for questions like this (Linux, macOS, Windows…?)

Remember to either quote or @mention others, so they are notified of your reply

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×