Версия java как узнать linux
Перейти к содержимому

Версия java как узнать 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

The simplest way is:

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.

Luis Alvarado's user avatar

This command should tell you what is currently providing the Java virtual machine ( java ) and the Java compiler ( 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:

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:

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:

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.

What Java Version Are You Running?

Frank Delporte

From time to time, you need to check which Java version is installed on your computer or server, for instance when starting on a new project or configuring an application to run on a server.

But did you know there are multiple ways you can do this and even get much more information than you might think, very quickly?

Reading the Java Version in the Terminal

Probably the easiest way to find the installed version is by using the java -version terminal command:

Checking Version Files in the Installation Directory

The above output results from info read by the java executable from a file inside its installation directory.

Let’s explore what we can find there.

On my machine, as I use SDKMAN to switch between different Java versions, all my versions are stored here:

And in each of these directories a release file can be found which also shows us the version information, including some extra information.

Getting More Information With showSettings

In 2010, an experimental flag (indicated with the X ) was added to OpenJDK to provide more configuration information: -XshowSettings .

This flag can be called with different arguments, each producing an other information output.

The cleanest way to call this flag, is by adding -version , otherwise you will get the long Java manual output as no application code was found to be executed.

Reading the System Properties

By using the -XshowSettings:properties flag, a long list of various properties is shown.

If you ever faced the problem of an unsupported Java version 59 (are similar), you’ll now also understand where this value is defined, it’s right here in this list as java.class.version .

It’s an internal number used by Java to define the version.

  • Java release > Class version
  • 8 > 52
  • 9 > 53
  • 10 > 54
  • 11 > 55
  • 12 > 56
  • 13 > 57
  • 14 > 58
  • 15 > 59
  • 16 > 60
  • 17 > 61
  • 18 > 62
  • 19 > 63

Reading the Locale Information

In case you didn’t know yet, I live in Belgium and use English as my computer language, as you can see when using the -XshowSettings:locale flag:

Reading the VM Settings

With the -XshowSettings:vm flag, some info is shown about the Java Virtual Machine.

As you can see in the second example, the amount of maximum heap memory size can be defined with the -Xmx flag.

Reading all at Once

If you want all of the information above with one call, use the -XshowSettings:all flag.

Conclusion

Next to java -version , we can also use java -XshowSettings:all -version to get more info about our Java environment.

Команда проверки версии Java в Linux

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

JAVA

Понимание Java

Что такое Java?

Java — это высокоуровневый объектно-ориентированный язык программирования, основанный на классах, который разработан таким образом, чтобы иметь как можно меньше зависимостей от реализации. Это язык программирования общего назначения, позволяющий разработчикам приложений писать один раз, выполнять везде (WORA), что означает, что скомпилированный код Java может работать на всех платформах, поддерживающих Java, без необходимости перекомпиляции.
Почему важна версия Java?

Знать версию Java, установленную в вашей системе, очень важно по нескольким причинам. Это помогает в отладке проблем, связанных с Java Runtime Environment (JRE). Это также помогает обеспечить совместимость между вашей системой и программным обеспечением, которое вы пытаетесь запустить. Некоторые приложения требуют определенной версии Java для правильной работы, и знание версии Java может избавить вас от возможных головных болей в будущем.

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

Шаг 1: Откройте терминал

Начните с открытия терминала. Если вы находитесь на сервере, вы уже там. Если вы используете Linux, найдите «Терминал» в меню приложений или на панели задач и откройте его. Не беспокойтесь о том, какой терминал вы используете, так как большинство наших команд работают в большинстве из них.

Шаг 2: Введите команду Java Version

Открыв терминал, вы можете проверить версию Java, введя следующую команду:

Эта команда указывает Java вывести информацию о своей версии. Если Java установлена в вашей системе, вы должны увидеть результат, подобный следующему:

В этом примере мы показываем версию Java 17.0.7. Ваша система может показывать другую версию, в зависимости от того, что у вас установлено.

Шаг 3: Понимание вывода

Вывод команды java -version содержит несколько частей информации:

  • java version «17.0.7» 2023-04-18 LTS: Это версия Java, установленная в вашей системе. LTS» означает, что это версия Long-Term Support, то есть она будет получать обновления и исправления безопасности в течение более длительного периода, чем версии, не относящиеся к LTS.
  • Java(TM) SE Runtime Environment (сборка 17.0.7+8-LTS-224): Это среда выполнения, которая представляет собой программный слой, на котором выполняются ваши Java-программы.
  • Java HotSpot(TM) 64-Bit Server VM (build 17.0.7+8-LTS-224, mixed mode, sharing): Это виртуальная машина Java (JVM), которая является платформой, исполняющей байткод Java. Смешанный режим» означает, что JVM использует для выполнения интерпретированный и скомпилированный код, а «совместное использование» означает, что она использует совместное использование данных классов для улучшения запуска и занимаемой площади.

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

Команда Java не найдена

Если вы вводите команду java -version и получаете сообщение java: command not found, это означает, что Java не установлена в вашей системе или исполняемый файл Java отсутствует в PATH вашей системы.

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

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.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *