Check if jdk is installed linux

How to verify if Java is installed on rhel

I stood up rhel VM. I was curious if JDK is installed or not so that I ran a command from a shell (bash).

lrwxrwxrwx 1 root root 26 May 2016 10:52 java -> /usr/java/default/bin/java 
java -bash: java: command not found 

It looks like java has symbolic link but /usr/java/default/bin/java is no longer exists. I just want to verify whether java (jdk) is installed or not but from what I’ve seen I am not too sure. I would like to believe that it is not installed if so why the system returned java: /usr/bin/java?

First: rpm -qa | grep jdk to search for other JDKs installed through package manager. Second, it may be missing a configured java alternative. You may need to configure java alternatives to deal with java , javac , javaws and other related to jdk — wiki.centos.org/HowTos/JavaRuntimeEnvironment

2 Answers 2

I would like to believe that it is not installed if so why the system returned java: /usr/bin/java?

whereis doesn’t resolve the symlink. So if /usr/bin/java still exist, even though the symlink target is broken, it will still return java: /usr/bin/java . I recommend you use type -a java to get the correct result. Please note that the symlink target OR non-symlink source file, both must be executable ( chmod +x to set it), otherwise type -a command will return not found even though file exist ( type will still return regardless of executable).

So, I can simplify like below:

whereis: Still return found even symlink broken or non-executable.

type: Return found even non-executable, and return not found if symlink broken.

type -a: Return not found when symlink is broken or non-executable.

All of them will return not found if the input file doesn’t exist.

So, what I can advise is install the JDK again, which «Oracle JDK» is preferred over than «OpenJDK».

A good article can be found here.

This is what you can do (Assume your system are x64):

sudo rpm -ivh jdk-8u91-linux-x64.rpm sudo rpm -ivh jdk-8u91-linux-x64-demos.rpm 

The version number of 8u91 version above is keep updating, so you should always visits Oracle websites to find out the latest version. Click the JDK DOWNLOAD button will go to this page which shows the latest version number and its correct filename.

You can also download the docs which the real link can be found here page, and unzip it (Assume your JDK has been installed at /usr/java/jdk1.8.0_91/ ):

sudo unzip jdk-8u91-docs-all.zip -d /usr/java/jdk1.8.0_91/ #optional 

Then use this two commands to choose the correct javac and java. I believe you only have one option (This sample shows jdk1.8.0_74 due to mine is not the latest 8u91):

$ sudo alternatives --config javac There are 2 programs which provide 'javac'. Selection Command ----------------------------------------------- *+ 1 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.fc21.x86_64/bin/javac 2 /usr/java/jdk1.8.0_74/bin/javac Enter to keep the current selection[+], or type selection number: 2 $ $ sudo alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- * 1 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.fc21.x86_64/jre/bin/java + 2 /usr/java/jdk1.8.0_74/jre/bin/java Enter to keep the current selection[+], or type selection number: 2 $ 

Thank you for your kind explanation especially in regards to the first question I had. It turns out that jdk is missing and I re-installed it.

Читайте также:  Reaver with kali linux

You may have to configure Alternatives to point to java, its explained in my link.

I have noticed with trying to keep Oracle Java installed over the openjdk that you have to make sure everything is linking correct and running the correct version of java.

If using an RPM system machine, I used the steps in the link below for getting it to work.

The Java command below would work as a validation that the Alternatives have been setup correctly.

java -version [root@somecomputer thebtm]# java -version java version "1.8.0_77" Java(TM) SE Runtime Environment (build 1.8.0_77-b03) Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode) 

Another side node is that if you already have Oracle Java installed and you download and install a newer java rpm, you have to update alternatives to point to the new version of java

[root@somecomputer thebtm]# alternatives --config java There are 5 programs which provide 'java'. Selection Command ----------------------------------------------- * 1 /usr/java/jdk1.8.0_66/bin/java 2 /usr/java/jdk1.8.0_66/jre/bin/java 3 /usr/java/jre1.8.0_77/bin/java 4 /usr/java/jdk1.8.0_77/jre/bin/java + 5 /usr/java/jre1.8.0_91/bin/java Enter to keep the current selection[+], or type selection number: 5 [root@somecomputer thebtm]# java -version java version "1.8.0_91" Java(TM) SE Runtime Environment (build 1.8.0_91-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode) 

Источник

How to tell if JRE or JDK is installed

I have one computer that I intentionally installed JDK on. I have another computer with JRE, for, among other things, testing. However, when I got a java application working on this computer, and then tried it on another, it complained that JDK was required. How can I check if JDK was somehow installed on my system? Note: the computer in question is a Mac.

Can you post the full text of the error, including how you’re trying to run it? You don’t need the JDK to run a Java program, just the JRE.

It was a friends computer- something about installing command line tools. I’ll comment again when I get a chance to inspect it again.

It sounds like you might be talking about making sure that Java is on your path, but that’s just a guess. Either way, you only need the JRE to run Java programs. You need the JDK to compile them.

Only few java programs need a JDK, IDEs, servlet containers like tomcat to compile JSPs and some others. What kind of application has the problem?

6 Answers 6

You can open up terminal and simply type

java -version // this will check your jre version javac -version // this will check your java compiler version if you installed 

this should show you the version of java installed on the system (assuming that you have set the path of the java in system environment).

Читайте также:  Удалить файл через консоль linux

And if you haven’t, add it via

export JAVA_HOME=/path/to/java/jdk1.x 

and if you unsure if you have java at all on your system just use find in terminal

@Pacerier Why ?? i do not know that for sure lol!. Maybe you do not have JDK installed ? Running windows or linux ??

Normally a jdk installation has javac in the environment path variables . so if you check for javac in the path, that’s pretty much a good indicator that you have a jdk installed.

I realize that the OP was asking about a Mac, so it may be different there. But as for Windows, this test does not seem reliable. I just checked, and I do NOT have javac in my path, but I DO have a jdk installed. (In my case, my JAVA_HOME is pointed to C:\Program Files\Java\jdk1.8.0_45 )

@maciej-cygan described the process well, however in order to find your java path:

it gives you the path of java binary file which is a linked file in /usr/bin directory. next:

$ cd /usr/bin/ && ls -la | grep java

find the pointed location which is something as follows (for me):

enter image description here

then cd to the pointed directory to find the real home directory for Java. next:

which is as follows in this case:

enter image description here

so as it’s obvious in the screenshot, my Java home directory is /usr/lib/jvm/java-11-openjdk-amd64 . So accordingly I need to add JAVA_HOME to my bash profile ( .bashrc , .bash_profile , etc. depending on your OS) like below:

A generic, pure Java solution..

For Windows and MacOS, the following can be inferred (most of the time).

public static boolean isJDK() < String path = System.getProperty("sun.boot.library.path"); if(path != null && path.contains("jdk")) < return true; >return false; > 

However. on Linux this isn’t as reliable. For example.

  • Many JREs on Linux contain openjdk the path
  • There’s no guarantee that the JRE doesn’t also contain a JDK.

So a more fail-safe approach is to check for the existence of the javac executable.

public static boolean isJDK() < String path = System.getProperty("sun.boot.library.path"); if(path != null) < String javacPath = ""; if(path.endsWith(File.separator + "bin")) < javacPath = path; >else < int libIndex = path.lastIndexOf(File.separator + "lib"); if(libIndex >0) < javacPath = path.substring(0, libIndex) + File.separator + "bin"; >> if(!javacPath.isEmpty()) < return new File(javacPath, "javac").exists() || new File(javacPath, "javac.exe").exists(); >> return false; > 

Warning: This will still fail for JRE + JDK combos which report the JRE’s sun.boot.library.path identically between the JRE and the JDK. For example, Fedora’s JDK will fail (or pass depending on how you look at it) when the above code is run. See unit tests below for more info.

# Unix java -XshowSettings:properties -version 2>&1|grep "sun.boot.library.path" # Windows java -XshowSettings:properties -version 2>&1|find "sun.boot.library.path" 
 # PASS: MacOS AdoptOpenJDK JDK11 /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib # PASS: Windows Oracle JDK12 c:\Program Files\Java\jdk-12.0.2\bin # PASS: Windows Oracle JRE8 C:\Program Files\Java\jre1.8.0_181\bin # PASS: Windows Oracle JDK8 C:\Program Files\Java\jdk1.8.0_181\bin # PASS: Ubuntu AdoptOpenJDK JDK11 /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/lib # PASS: Ubuntu Oracle JDK11 /usr/lib/jvm/java-11-oracle/lib # PASS: Fedora OpenJDK JDK8 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.fc24.x86_64/jre/lib/amd64 #### FAIL: Fedora OpenJDK JDK8 /usr/java/jdk1.8.0_231-amd64/jre/lib/amd64 

Источник

How to Check Java Version Installed on Linux

How do I check my current Java version? There are several ways to check if Java is installed and which version is running on your system.

Читайте также:  Audio plugins on linux

In this tutorial, learn how to check the Java version installed on Linux distros, including Ubuntu, CentOS, and Debian.

tutorial on checking Java version on linux

  • A user account with sudo privileges
  • Access to the command-line/terminal window
  • A version of Java

Method 1: Check the Java Version On Linux

To check the Java version on Linux Ubuntu/Debian/CentOS:

2. Run the following command:

3. The output should display the version of the Java package installed on your system. In the example below, OpenJDK version 11 is installed.

example of checking the version of java running on ubuntu linux

Note: If the output indicates there is no such package on the system, you can install it with the help of one of our guides – How to install Java on Ubuntu or How to Install Java on CentOS.

You can also check the version of the primary Java compiler – javac (pronounced “java-see”) with the command:

Check javac version on Ubuntu.

Method 2: Find Version by Checking Path Where Java is Installed

There are two ways to find the path of the Java directory.

The first option includes running a single command:

update-alternatives --list java

The system should respond with the path where Java is installed.

Check Java directory path to find the java installation version

Note: This option may not work on CentOS systems. If you have issues finding the path of the Java directory with the command above, use the alternative outlined below.

Alternatively, you can use the whereis command and follow the symbolic links to find the Java path.

Check Java path on Ubuntu.

The output tells you that Java is located in /usr/bin/java.

2. List the content of the /usr/bin/java directory:

Locate Java directory on Ubuntu.

Inspecting the directory shows that /usr/bin/java is only a symbolic link for /etc/alternatives/java.

3. Just like in the previous step, list the content of the provided path by running:

Find Java path on Ubuntu.

Finally, the output displays /etc/alternatives/java is another symbolic link and that the real path of the Java directory is /usr/lib/jvm/java-11-openjdk-amd64/bin/java.

Method 3: Search for Java in the Installed Packages List

You can also prompt the system to list installed packages and search for Java, with its version number.

Find Java by listing all installed packages.

1. To generate a list of all installed packages, use the command:

2. Scroll up/down until you find the Java packages as shown in this example.

Find Java in the installed packages list.

To avoid searching through all installed packages, list Java packages only. Prompt the system to list a specific software package. In this case, the package name is openjdk:

sudo apt list --installed | grep -i openjdk

Search for Java in the Installed packages list on Ubuntu.

Note: CentOS users need to modify the commands for listing installed packages for their package manager. Use the commands: sudo yum list installed and sudo yum list installed | grep -i openjdk instead.

With this article, you have successfully checked the Java version installed on Linux. We also covered checking the Java path and searching for Java among the installed packages.

Once the Java version is confirmed, you can start developing anything from lightweight mobile to desktop applications.

Источник

Оцените статью
Adblock
detector