How to find path where jdk installed?

841,214

Solution 1

Try either of the two:

$ which java

$ whereis java

For your first java program read this tutorial:

"Hello World!" for Solaris OS and Linux

Solution 2

On RHEL7, I used

locate openjdk

and it led me to the /usr/lib/jvm/ directory which contained the directories:

java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/
jre/
jre-1.8.0/
jre-1.8.0-openjdk/
jre-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/
jre-openjdk/

Each of these contain a bin/java

To find the full path of the symbolic link use:

readlink -f $(which java)

*Credit: Answer on Stack Overflow

**Note: I'm answering here as it was the first result in Google

Solution 3

You can list the installed files with

rpm -ql packagename

You will see somewhere a bin directory with java executable

But if the JDK RPM was correctly installed you should already find java in you path.

Try

javac MyFirstJavaClass.java

and if everything compiles

java MyFirstClass

(If you didn't change anything the current directory . should already be in your class path)

Solution 4

Since this question is RPM specific, rpm is the way to get started (as answered by @Matteo).

rpm flags

-q is short for --query
-l is short for --list

Example

rpm -ql jdk1.8.0_20 | grep "jdk1.8.0_20/bin$"
/usr/java/jdk1.8.0_20/bin

Knowing this may be desirable for setting a user or application's $JAVA_HOME variable. This is often needed when a system has multiple versions of java installed, or multiple distributions of java installed, such as OpenJDK and Oracle/Sun.

$JAVA_HOME Example

In the ~/.bash_profile, or related file (.bashrc, .zshrc, .cshrc, setenv.sh), something similar to the below may be used.

JAVA_HOME='/usr/java/jdk1.8.0_20'
export JAVA_HOME
PATH="$JAVA_HOME/bin:$PATH"
export PATH

If you would like more control over where Java gets installed, such as in /opt, then the tarball can be used instead of the RPM file.


Other similar questions, are asking about how to find any binary or file, in the general case.

Share:
841,214

Related videos on Youtube

Terry
Author by

Terry

@faisal6621 facebook linkedin Er. Mohammad Faisal (Blogger) Er. Mohammad Faisal (Wordpress) If you are looking for something to vote on, I'm looking for votes (ideally upvotes 🤪) on [my questions/answers with zero][1]...

Updated on September 18, 2022

Comments

  • Terry
    Terry over 1 year

    I've installed jdk1.7.0.rpm package in RHEL6.
    Where I do find the path to execute my first java program?

    • sakisk
      sakisk over 12 years
      Possible duplicate of 18472
    • rozcietrzewiacz
      rozcietrzewiacz over 12 years
      Hi, Mohammad. It's not a stupid question, but one that has been answered in several places already - like this or this question.
  • Kevin
    Kevin over 7 years
    In general, I highly recommend using the mlocate package for finding things on a Red Hat based Linux's file system.
  • bcasasus
    bcasasus almost 7 years
    Note these commands give different results. If you are interested in the non-symlink path use whereis java.
  • Tim S.
    Tim S. almost 7 years
    I don't really think this answers the question. The java binary gets installed with the JRE, but if you're doing development you need JDK, which isn't necessarily installed in which java (which in my case is /usr/bin).
  • Tim S.
    Tim S. almost 7 years
    This should be the accepted answer IMO.
  • Noumenon
    Noumenon over 5 years
    This gave me mostly JDK6 even though java -version gave me 1.8. There was one link to the JDK8 folder near the top.
  • Læti
    Læti over 4 years
    type java is a more cross-platform method, as it's built into every major posix shell.