Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

no JAVA_HOME in the path

2 views
Skip to first unread message

Amn

unread,
Aug 23, 2022, 9:30:05 AM8/23/22
to

When I type echo $JAVA_HOME, Debian 11's Konsole displays ... nothing, 'echo $PATH' reports - /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin:libtool: /usr/bin/libtool /usr/share/libtool /usr/share/man/man1/libtool.1.gz -
However if I type, 'java --version' I get - /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin:libtool: /usr/bin/libtool /usr/share/libtool /usr/share/man/man1/libtool.1.gz -, which is correct.
Where is $JAVA_HOME set or how do I add it to the path permanently?

Thanks in advance.

Amn

unread,
Aug 23, 2022, 9:50:05 AM8/23/22
to
Thank you for your prompt response.
Adding Java to the $PATH variable requires me to know the location where
Java was installed, which I don't know. Is there a way to find out where
Java was installed?


On 2022-08-23 9:40 a.m., Roberto C. Sánchez wrote:
> On Tue, Aug 23, 2022 at 09:21:38AM -0400, Amn wrote:
>> When I type echo $JAVA_HOME, Debian 11's Konsole displays ... nothing,
>> 'echo $PATH' reports -
>> /usr/local/[1]bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin:libtool:
>> /usr/bin/libtool /usr/share/libtool /usr/share/man/man1/libtool.1.gz -
>> However if I type, 'java --version' I get -
>> /usr/local/[2]bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin:libtool:
>> /usr/bin/libtool /usr/share/libtool /usr/share/man/man1/libtool.1.gz -,
>> which is correct.
>> Where is $JAVA_HOME set or how do I add it to the path permanently?
>>
> You have to set it yourself.
>
> Options include /etc/bashrc, /etc/profile, /etc/profile.d,
> /etc/environment, /etc/environment.d, and possibly others, for setting
> it system-wide, and their per-user counterparts in $HOME for setting it
> on a per-user basis.
>
> Regards,
>
> -Roberto
>

Roberto C. Sánchez

unread,
Aug 23, 2022, 9:50:05 AM8/23/22
to
On Tue, Aug 23, 2022 at 09:21:38AM -0400, Amn wrote:
> When I type echo $JAVA_HOME, Debian 11's Konsole displays ... nothing,
> 'echo $PATH' reports -
> /usr/local/[1]bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin:libtool:
> /usr/bin/libtool /usr/share/libtool /usr/share/man/man1/libtool.1.gz -
> However if I type, 'java --version' I get -
> /usr/local/[2]bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin:libtool:
> /usr/bin/libtool /usr/share/libtool /usr/share/man/man1/libtool.1.gz -,
> which is correct.
> Where is $JAVA_HOME set or how do I add it to the path permanently?
>
You have to set it yourself.

Options include /etc/bashrc, /etc/profile, /etc/profile.d,
/etc/environment, /etc/environment.d, and possibly others, for setting
it system-wide, and their per-user counterparts in $HOME for setting it
on a per-user basis.

Regards,

-Roberto

--
Roberto C. Sánchez

to...@tuxteam.de

unread,
Aug 23, 2022, 10:10:06 AM8/23/22
to
On Tue, Aug 23, 2022 at 09:49:10AM -0400, Amn wrote:
> Thank you for your prompt response.
> Adding Java to the $PATH variable requires me to know the location where
> Java was installed, which I don't know. Is there a way to find out where
> Java was installed?

Wait. I think you are confusing two things: PATH is where your shell goes
to look for your binaries. Has *nothing* to do with java. JAVA_HOME is
where your java installation finds its things. If you are using the
java installation provided by your distribution, it shouldn't be necessary
to set it.

You only have to set it when you have an alternative java installation
which *you* have installed yourself and your distribution doesn't know
about. But then you know what you are doing and know how to set that
variable.

HTH
--
t
signature.asc

rudu

unread,
Aug 23, 2022, 10:40:05 AM8/23/22
to
Maybe this could help :

$ java -version
openjdk version "11.0.16" 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Debian-1)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Debian-1, mixed mode,
sharing)

$ update-alternatives --config java
Il existe 6 choix pour l'alternative java (qui fournit /usr/bin/java).

  Sélection   Chemin Priorité  État
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111     
mode automatique
  1            /usr/lib/jvm/java-1.5.0-sun/jre/bin/java 53        mode
manuel
  2            /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1101     
mode manuel
* 3            /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111     
mode manuel
  4            /usr/lib/jvm/java-6-sun/jre/bin/java 63        mode manuel
  5            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081     
mode manuel
  6            /usr/lib/jvm/oracle-java8-jdk-amd64/jre/bin/java
318       mode manuel

Appuyez sur <Entrée> pour conserver la valeur par défaut[*] ou
choisissez le numéro sélectionné :

(Sorry, it's french)

Rudu

Markus Schönhaber

unread,
Aug 23, 2022, 11:00:05 AM8/23/22
to
23.08.22, 15:49 +0200, Amn:

> Thank you for your prompt response.
> Adding Java to the $PATH variable requires me to know the location where
> Java was installed, which I don't know. Is there a way to find out where
> Java was installed?

As Tomas wrote, the more interesting question than *how* to set
JAVA_HOME, is *why* you want to set it in the first place.

That said, on Linux package managers often install JVMs in a
subdirectory of /usr/lib/jvm.
To find out what the java binary in your PATH thinks about where it's
home is, you can do, for example

java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home'

On debian

update-alternatives --display java

should show you the Java installations the system knows about.

And, of course, a tool like dpkg could be used to show which files are
installed by the package manager...

--
Regards
mks

David Wright

unread,
Aug 23, 2022, 11:20:05 AM8/23/22
to
Not as bad as the OP's use of HTML. I've looked at that post in its
text version, the raw HTML, as rendered by lynx, and in firefox,
and it looks as though the PATH ends with a colon.

So I'll just point out that if you want the current directory in
your PATH, then make it explicit with a period, as in:

… … …games:/usr/games:/snap/bin:libtool:.

and if you don't, then remove the final colon, as in:

… … …games:/usr/games:/snap/bin:libtool

If ever you want to run, say, foo in your current directory,
then just type:

$ ./foo

But in view of the newish semantics for su, I'd strongly advise
against having PATH include the directory that you just happened
be in at the moment.

Cheers,
David.

Amn

unread,
Aug 26, 2022, 10:10:05 PM8/26/22
to
Thanks!
The problem is solved.

On 2022-08-23 9:40 a.m., Roberto C. Sánchez wrote:

Roland Müller

unread,
Sep 27, 2022, 2:40:06 PM9/27/22
to
Hello,

here is some clarification of the relationship between JAVA_HOME and the
PATH.

JAVA_HOME points to the base directory of a Java JRE or JDK
(=development) directory. Under $JAVA_HOME one should find a bin
directory which contains java, javac and other binaries.

In the case you just need the wanted java or javac in the execution path
actually JAVA_HOME is not needed. Simple hello-world like compilations
from command line work ok when java(c) is in path.

Java based tools make typically use of JAVA_HOME and some of them refuse
to start unless JAVA_HOME is set to a valid location. E.g. Maven even
prefers JAVA_HOME over the version of javac that is in the execution path:

$ $ echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk

$ mvn -v
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555;
2019-04-04T22:00:29+03:00)
Maven home: /opt/maven/apache-maven-3.6.1
Java version: 11.0.16.1, vendor: Red Hat, Inc., runtime:
/usr/lib/jvm/java-11-openjdk-11.0.16.1.1-1.fc36.x86_64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.19.10-200.fc36.x86_64", arch: "amd64",
family: "unix"

but

$ java -version
openjdk version "17.0.4.1" 2022-08-12
OpenJDK Runtime Environment (Red_Hat-17.0.4.1.1-1.fc36) (build 17.0.4.1+1)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.4.1.1-1.fc36) (build 17.0.4.1+1,
mixed mode, sharing)


BR,

Roland
0 new messages