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

  • 2
    Possible duplicate of 18472
    – sakisk
    Commented Sep 29, 2011 at 9:31
  • 2
    Hi, Mohammad. It's not a stupid question, but one that has been answered in several places already - like this or this question. Commented Sep 29, 2011 at 9:40
  • 1
    Just an PS: on MacOS, Java is usually installed at '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home', where the version number could be different. Commented Jan 19, 2015 at 19:05

4 Answers 4


Try either of the two:

$ which java

$ whereis java

For your first java program read this tutorial:

"Hello World!" for Solaris OS and Linux

  • 1
    Note these commands give different results. If you are interested in the non-symlink path use whereis java. Commented May 18, 2017 at 1:50
  • 3
    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.
    Commented Jun 21, 2017 at 13:15
  • 1
    type java is a more cross-platform method, as it's built into every major posix shell.
    – user213102
    Commented Jan 28, 2020 at 18:13

On RHEL7, you can use locate:

locate openjdk

or find:

find / -iname "*openjdk-*"

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


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

  • This gave me mostly JDK6 even though java -version gave me 1.8. There was one link to the JDK8 folder near the top.
    – Noumenon
    Commented Sep 19, 2018 at 2:35
  • 1
    Thank you. The readlink -f $(which java) was exactly what I was looking for.
    – BugSquanch
    Commented Nov 25, 2021 at 14:23

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.


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)

  • This should be the accepted answer IMO.
    – Tim S.
    Commented Jun 21, 2017 at 13:15

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


rpm -ql jdk1.8.0_20 | grep "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.

export JAVA_HOME
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.

  • In general, I highly recommend using the mlocate package for finding things on a Red Hat based Linux's file system.
    – Kevin
    Commented Jan 24, 2017 at 18:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .