Get java version in linux

How can I tell what version of Java I have installed?

I want to start toying around with java (eventually getting to the point where I can write basic little programs for android or web), but I’ve managed to have java messed up on my computer (from past experiments). I’m not sure which version of java I have, and would like to know if there is a command to see the version of java that is installed and active. Also, which version works best? All this on 32bit Ubuntu 12.04 EDIT:
Ok, so it seems like I have both openjdk 6 and 7, with openjdk 7 in use. I want to use openjdk 7, so how do I uninstall openjdk 6? Is just via USC good enough or is there a command that should be run?

4 Answers 4

update-java-alternatives -l shows you all the Java versions you have installed.

java -version shows you the Java version you are using.

java -showversion shows you the Java version you are using and help.

Normally it would be OpenJDK.

This command should tell you what is currently providing the Java virtual machine ( java ) and the Java compiler ( javac ):

file /etc/alternatives/java /etc/alternatives/javac 

This assumes the «alternatives» system is working properly, which might not be the case, depending on how Java has been «messed up» in the past. To check this, run:

If the alternatives system is working correctly and being used by Java, then you should see:

/usr/bin/java: symbolic link to `/etc/alternatives/java' /usr/bin/javac: symbolic link to `/etc/alternatives/javac' 

Otherwise please edit your question to provide details. Then it should be possible to give a more specific answer.

You can remove openjdk-6 with the Software Center. There are multiple packages associated with it, so you may need to remove more than one packages. (All the `openjdk-6 packages are listed here.)

Or you can use the command-line:

sudo apt-get remove openjdk-6-\* icedtea-6-\* 

However, whichever method you use, you may want to check first to see what depends on these packages—you might have software installed that specifically needs version 6. (Probably not, but possibly.)

You can check for this by simulating the removal operation on the command-line:

apt-get -s remove openjdk-6-\* icedtea-6-\* 

This will show you the effects of removing those packages, including what other packages would be removed as well. (You’ll notice that since this is a simulation, you don’t need sudo .)

Читайте также:  Clamav для линукс минт

If you want to be able to continue using Java content online in your web browser (this is not the same thing as JavaScript), then before you remove any icedtea-6- or openjdk-6- packages (except perhaps openjdk-6-jdk ), you should make sure you have icedtea-7- packages installed corresponding to whatever icedtea-6- packages are installed.

Источник

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.

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.

Читайте также:  Linux параметры сетевого интерфейса

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.

Источник

How to check java version at linux (RedHat6)

enter image description here

I am trying to check what java version I have installed in my linux machine, I have tried:

the console is returning nothing and getting stuck in a «java mode» , feels like the command called java and its waiting for my inputs, any thing I type then returns nothing. until I type crt+C it exits the mode.

3 Answers 3

If your java version more than 1.6 then it should work

if version is not installed it returns error message

Please share some snapshot so i can rectify it

To answer your question directly, you can use

For future Referenecs . You can try any of these commands.

rpm -qi «package_name_without_quotes»

It gives information of installed package. To display information about one or more packages (glob expressions are valid here as well), use the following command :

yum info «package_name_without quotes»

yum list «package_name_without_quotes»

yum —showduplicates list «package_name_without_quotes»

The yum info package_name command is similar to the rpm -q —info package_name command, but provides as additional information the ID of the Yum repository the RPM package is found in.

You can also query the Yum database for alternative and useful information about a package by using the following command :

yumdb info «package_name_without_quotes»

This command provides additional information about a package, including the check sum of the package (and algorithm used to produce it, such as SHA-256), the command given on the command line that was invoked to install the package (if any), and the reason that the package is installed on the system.

Источник

Check Java Version in Linux

Check Java Version in Linux

  1. Use the version Command to Check Java Version in Linux
  2. Display Path to Check Java Version in Linux
  3. Use the whereis Command to Check the Java Version in Linux
  4. Conclusion

In this article, we shall learn to check the Java version on our Linux machine. We would additionally see the method to update the Java version.

Use the version Command to Check Java Version in Linux

Linux provides us with several different commands that we can execute from the terminal. One such command is the version command.

The man page of the version command displays the OpenSSL version number of software installed on Linux.

Читайте также:  Linux mint ускорение системы

We will follow the below steps on a Linux machine to get the version number of Java.

Open the Linux terminal.
Execute the following command.
If Java is installed on your machine, it will show the OpenJDK version.

Let us see a working example to check the version of Java.

stark@stark:~$ java -version openjdk version "11.0.13" 2021-10-19 OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.18.04) OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.18.04, mixed mode, sharing) 

To read the Linux manual page of the version command, you can execute the man command in the Linux terminal.

This command will display all the information related to the version command.

Display Path to Check Java Version in Linux

Other than the method given above, we can try to display the path of where Java is installed. In this way, we will get the version of Java because the path is shown with a full package name that includes the version information.

To check the version using this method, execute the following command in your Linux terminal.

update-alternatives --list java 
/usr/lib/jvm/java-11-openjdk-amd64/bin/java 

Note that the output can vary depending on your machine and Java version.

Use the whereis Command to Check the Java Version in Linux

We can also use the whereis Linux command to check the version of Java installed on our machine. However, we will not get the version of Java directly using this command.

The whereis command lists the path of Java installed on the machine. We can then list all the directory contents recursively until we get the Java package listed as an item.

We can then check the version number, a suffix of the package name.

Let us understand this method with the help of an example.

stark@stark:~$ whereis java java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz 

We will then list the contents of ‘/usr/bin/java’ by executing the ls command.

stark@stark:~$ ls -l /usr/bin/java lrwxrwxrwx 1 root root 22 Apr 28 2019 /usr/bin/java -> /etc/alternatives/java 

You should note that -l is a flag that denotes the long-listed format for contents.

Further, we will list all contents of ‘/etc/alternatives/java’ using the ls command.

stark@stark:~$ ls -l /etc/alternatives/java lrwxrwxrwx 1 root root 43 Apr 28 2019 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java 

You can see that we get ‘java-11-openjdk-amd64’ in the output. Thus, we got the version of Java installed on our machine.

Conclusion

We have seen three different methods to check the version of Java installed on our machine. You can use one of the methods as per your needs.

Apart from the methods given in this article, you can use third-party libraries such as yum or rpm to check the version of Java.

However, these libraries have a drawback: we should give them the package’s exact name to know the version or path information, making them difficult to use.

Related Article — Java Version

Copyright © 2023. All right reserved

Источник

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