- Как проверить версию Java
- Управление версиями Java
- Проверка версии Java
- Выводы
- How to Check Java Version Installed on Linux
- Method 1: Check the Java Version On Linux
- Method 2: Find Version by Checking Path Where Java is Installed
- Method 3: Search for Java in the Installed Packages List
- How to Check and Update Java Version on Ubuntu 22.04?
- How to check Java version on Ubuntu 22.04
- How to Update Java version on Ubuntu 22.04
- Conclusion
- About the author
- Anees Asghar
Как проверить версию 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 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.
- 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.
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:
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.
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.
The output tells you that Java is located in /usr/bin/java.
2. List the content of the /usr/bin/java directory:
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:
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.
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
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 and Update Java Version on Ubuntu 22.04?
Java is a general-purpose client-side programming language that serves several functionalities like android application development, game development, web applications development, and many other software products. To build any application, first, we have to install Java on our computer systems. However, some applications are not capable to run on java’s outdated version. So, it’s essential to know which Java version is installed on our operating system and if our machine is running an outdated version of java, then how to update it.
This post will explain how to check and upgrade the Java version on Ubuntu 22.04. So, let’s begin!
How to check Java version on Ubuntu 22.04
Open the terminal on your ubuntu 22.04 operating system and type the below-mentioned command to check which Java version is installed on your machine:
Once you typed the above-given command on the terminal, it will produce the following outcome:
The above snippet shows that Java is not installed on our machine. Now, let’s move one step further to learn how to install/upgrade the Java version on Ubuntu 22.04.
How to Update Java version on Ubuntu 22.04
To update the java version or to install the latest java version, firstly you have to upgrade the apt repository. To do so, type the below-given command on the terminal:
Next, run the below-enlisted command to install the default Java Runtime Environment(JRE) on your operating system:
When you execute the above-given command, it will work like this:
Type “Y” to continue the installation process:
The whole installation process will take a few minutes to install JRE on your system. You can verify the JRE’s installation by typing the following command:
If JRE is successfully installed on your Ubuntu 22.04, then you will witness the result something like this:
Congratulations! You have successfully installed the latest and updated version of Java on Ubuntu 22.04.
As the JRE’s installation is done, now you can run almost every java software on your machine. However, some java-oriented software may require the Java Development Kit(JDK) to compile/run some particular tasks. In such cases, you can install the JDK by typing the below-given command:
The above-given command will work something like this:
Type “Y” to continue the JDK’s installation process:
Type the below-given command on the terminal of ubuntu 22.04 to verify whether the updated JDK is installed on your machine or not:
You will witness the below-given output:
Congrats! You are running an updated Java version on your ubuntu 22.04.
Conclusion
Open the terminal and type “sudo apt install default-jre” to install JRE, and type “sudo apt install default-jdk” to install JDK on ubuntu 22.04. To check or verify the java version type “java -version” on the terminal of Ubuntu 22.04. This write-up provided a step-by-step guide on how to check, update, and verify the java version on ubuntu 22.04.
About the author
Anees Asghar
I am a self-motivated IT professional having more than one year of industry experience in technical writing. I am passionate about writing on the topics related to web development.