Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How important is setting environment variables in Java?

I am writing a blog where I have explain my students how to install Java, but I'm wondering why should expose them to this complicated part of Java installation. When I used Java before, I used right out of the box with my IDE. But all the tutorials I see mention configuration of these environment variables.

Maybe my PATH variables were set from previous installations, however I don't remember doing it.

Can anyone please advise if environment variable setting can be left to the IDEs or has to be done manually?

like image 387
Navin Israni Avatar asked May 12 '16 04:05

Navin Israni


People also ask

Why it is important to set environment variables?

Environment variables provide a good way to set application execution parameters that are used by processes that you do not have direct control over. However, environment variables should not be used for configuration values within your own dynamic applications. Environment variables are global variables.

What is the use of setting environment variables in Java?

Many operating systems use environment variables to pass configuration information to applications. Like properties in the Java platform, environment variables are key/value pairs, where both the key and the value are strings.

Do we need to set environment variables for JRE?

After you've installed Java in Windows, you must set the JAVA_HOME environment variable to point to the Java installation directory. This information is only relevant if you're installing Confluence manually on a Windows server.


2 Answers

Java does not need any environment variables to be set.

However, setting some environment variables makes some things easier.

  • PATH If the jre/bin folder is on the path, you don't have to qualify to run the java command. If the jdk/bin folder is on the path, you don't have to qualify to run the java and javac commands. As well as some other commands provided by Java.

  • JAVA_HOME Used by many Java programs and installers to find Java.

When using an IDE, it can usually find / prompt for Java installations, so it doesn't need any environment variables. The IDE won't set them either.

like image 170
Andreas Avatar answered Sep 28 '22 05:09

Andreas


As mentioned above, JAVA_HOME Used by many Java programs and installers to locate Java. for instance, Tomcat requires the environment variable JAVA_HOME to be set to the JDK installed directory.

To check if JAVA_HOME is already set, start a terminal and issue:

echo $JAVA_HOME

JAVA_HOME is to be set to the JDK installed directory. You need to find your JDK installed directory.

[TODO] find macOS and Ubuntu JDK installed directory.

Add the the following line at the end of "~/.bashrc" (or "~/.login"). Take note that filename beginning with dot (.) is hidden by default.

[TODO] How to un-hide for macOS/Ubuntu.

export JAVA_HOME=/path/to/JDK-installed-directory


// Verify the new setting
echo $JAVA_HOME
like image 34
Ikbel Avatar answered Sep 28 '22 06:09

Ikbel