Reputation: 1091
I used sudo apt-get open-jdk7
to install Java on my Ubuntu OS.
When I open a terminal and type echo $JRE_HOME
it displays nothing. But then I do java -version
it shows me correct version of OpenJDK. Also when I simply type java
it works.
Not sure how Ubuntu set the path of java.
Similarly javac
works but I don't see anything when I say echo $JAVA_HOME
.
My path does not show java directory path in it.
Where is Ubuntu setting the java path? Why does Ubuntu not set JAVA_HOME
and JRE_HOME
during installation of OpenJDK?
Upvotes: 1
Views: 5039
Reputation: 308249
It's a common misconception that Java somehow requires JAVA_HOME
, JRE_HOME
or similar environment variables to be set to work.
In fact the java
and javac
(and related) executables don't really care about those variables. They only need to be on the PATH
(or can be executed via a full path if not on PATH
) and will find their related install by looking "near itself" (i.e. the executable are usually installed in a known location relative to the JVM files).
There are a few third party scripts that use JAVA_HOME
and/or JRE_HOME
to find a Java installation (Apache Tomcat is a well-known example for this), but the Java executables themselves don't need those variables.
As to how Ubuntu finds the executables is easy to answer: use which java
and which javac
to find out which executables are executed when you type those commands. On Debian-based systems they are usually a series of symlinks through the alternatives systems that point to the actual executables.
Upvotes: 5
Reputation: 7174
As many Linux distros, Ubuntu has /etc/alternatives in its paths. If you type:
which java
Then you'll get
/etc/alternatives/java
If you type:
ls -l /etc/alternatives/java
Then you'll get
/etc/alternatives/java -> /usr/lib/jvm/<your java version>
A few mor ls -l -s can help you to get the full picture.
Upvotes: 1
Reputation: 2040
"Where is ubuntu setting java path?", ubuntu does not set the open-jdk-java-path automatically. try
find / -name "java"
to locate the javac. And write
export JRE_HOME="xxx"
(where xxx is the base of the open-jdk-jre.)
BTW: You got nothing than trouble with open-jdk. You better use the sun-jdk.
Upvotes: 1