Linux show java version

Как проверить версию Java

Java — один из самых популярных языков программирования в мире, используемый для создания различных типов кроссплатформенных приложений.

В этой статье объясняется, как с помощью командной строки проверить, какая версия Java установлена в вашей системе Linux. Это может быть полезно при установке приложений, требующих определенной версии Java.

Управление версиями Java

Java использует семантическое управление версиями . Версии готовых к выпуску релизов представлены по следующей схеме:

Например, в Java 11.0.8 11 — это основная версия, 0 — дополнительная версия, а 8 — версия безопасности.

  • MAJOR — Основные выпуски содержат новые возможности и функции.
  • MINOR — второстепенные выпуски содержат различные исправления ошибок и совместимые улучшения.
  • SECURITY — выпуски безопасности содержат критические исправления безопасности.

Проверка версии Java

Чтобы узнать, какая версия Java установлена в вашей системе, выполните команду java -version :

Команда отобразит версию Java по умолчанию:

openjdk 11.0.8 2020-07-14 OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04) OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, sharing) 

В этом примере в нашей системе установлена Java версии 11.0.8 . Версия, установленная в вашей системе, может отличаться.

Читайте также:  Тег А

Если вы получили сообщение «java: command not found», это означает, что Java не установлена в системе. Чтобы установить Java, воспользуйтесь одним из следующих руководств в зависимости от вашего дистрибутива Linux:

В системе также может быть установлено несколько версий Java одновременно. Чтобы проверить, есть ли на вашем компьютере несколько установок Java:

sudo update-alternatives --config java

Если у вас только одна установка Java, результат будет выглядеть примерно так:

There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-11-openjdk-amd64/bin/java Nothing to configure. 

В противном случае, если у вас несколько установок Java, команда отобразит меню, в котором вы можете выбрать, какая версия будет версией Java по умолчанию:

There are 3 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode Press to keep the current choice[*], or type selection number: 

Чтобы изменить версию Java по умолчанию, просто введите номер версии (число в столбце «Выбор») и нажмите Enter .

Выводы

Узнать, какая версия Java установлена в вашей системе Linux, очень просто, просто введите java -version .

Не стесняйтесь оставлять комментарии, если у вас есть вопросы.

Источник

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 .)

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.

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 On Linux | Ubuntu/Debian/CentOS

fivem server hosting

Java is one of the most popular and widely used programming languages around the globe. If you are a Java developer then you must have a knowledge of “how to check java version”. There are several methods to check which Java version installed in your system.

If you don’t know how to install Java, you should read my guide on How to Install Java on Ubuntu 20.04.

In the post, we will show you how to check java version on CentOS, Ubuntu and Debian operating systems.

Prerequisites

Check Java Version on Linux

If you want to check the Java version on Ubuntu, Debian or CentOS operating systems, open a command-line terminal and run the following command:

This will display the installed version of Java as shown below:

java -version openjdk version "11.0.9.1" 2020-11-04 OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04) OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

check java version ubuntu

You can also check the Java compiler version using the javac command as shown below:

You should see the Java compiler version in the following output:

check javac version linux

Check Java Version Using the Java Installation Path

You can also check the java version with the help of Java installation path. There is two way to find the Java installation directory or path.

The first method to find the Java installation path with the following command:

update-alternatives --list java

This will display the complete path of the Java as shown below:

/usr/lib/jvm/java-11-openjdk-amd64/bin/java

Note: For CentOS and RHEL operating system, run the following command:

You can also use the whereis command to check the Java path.

Run the whereis command as shown below:

You should see the following output:

java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz

Next, run the ls command to list the content of /usr/bin/java:

You should see the following output:

lrwxrwxrwx 1 root root 22 Feb 5 04:50 /usr/bin/java -> /etc/alternatives/java

In the above output, you should see that /usr/bin/java point to symbolic link /etc/alternatives/java.

Now, run the ls command again to list the content of /etc/alternatives/java.

This will display the complete path of the Java as shown below:

lrwxrwxrwx 1 root root 43 Feb 5 04:50 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java

check java version using path

Check Java Version by Searching in Installed Package List

You can also check the Java version to list installed packages and search for Java. For Ubuntu and Debian operating systems, follow the below steps:

You can use either apt or dpkg command to list all installed packages.

List all installed packages and search for Java using the apt command:

apt list --installed | grep -i openjdk

You should see the installed version of Java in the following output:

openjdk-11-jdk-headless/focal-updates,focal-security,now 11.0.9.1+1-0ubuntu1~20.04 amd64 [installed,automatic] openjdk-11-jdk/focal-updates,focal-security,now 11.0.9.1+1-0ubuntu1~20.04 amd64 [installed,automatic] openjdk-11-jre-headless/focal-updates,focal-security,now 11.0.9.1+1-0ubuntu1~20.04 amd64 [installed,automatic] openjdk-11-jre/focal-updates,focal-security,now 11.0.9.1+1-0ubuntu1~20.04 amd64 [installed,automatic]

List all installed packages and search for Java using the dpkg command:

You should see the installed version of Java in the following output:

ii openjdk-11-jdk:amd64 11.0.9.1+1-0ubuntu1~20.04 amd64 OpenJDK Development Kit (JDK) ii openjdk-11-jdk-headless:amd64 11.0.9.1+1-0ubuntu1~20.04 amd64 OpenJDK Development Kit (JDK) (headless) ii openjdk-11-jre:amd64 11.0.9.1+1-0ubuntu1~20.04 amd64 OpenJDK Java runtime, using Hotspot JIT ii openjdk-11-jre-headless:amd64 11.0.9.1+1-0ubuntu1~20.04 amd64 OpenJDK Java runtime, using Hotspot JIT (headless)

For CentOS and RHEL operating systems, follow the below steps:

You can use yum or dnf command to list all installed packages and search for Java as shown below:

yum list installed | grep -i openjdk

This will display the installed version of Java as shown below:

java-11-openjdk.x86_64 1:11.0.9.11-3.el8_3 @AppStream java-11-openjdk-devel.x86_64 1:11.0.9.11-3.el8_3 @AppStream java-11-openjdk-headless.x86_64 1:11.0.9.11-3.el8_3 @AppStream

Conclusion

In the above guide, you learned a different method of how to check the Java version on Linux. You can now any of the above methods to check the Java version.

Источник

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