- What is command to see all java versions installed on linux?
- 5 Answers 5
- 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
- Как удалить Java в Ubuntu
- Как удалить Java в Ubuntu 20.04
- 1. Как узнать тип Java
- 2. Как узнать версию Java
- 3. Как узнать способ установки Java
- 4. Удаление Java
- Выводы
- How can I tell what version of Java I have installed?
- 4 Answers 4
What is command to see all java versions installed on linux?
I know about java -version. I don’t care what version I’m currently running. I care what other versions are installed on my linux box. If it’s another java -* command I didn’t see it in the java -help. I’ve tried googling it but the answers are either for Windows or they say «use java -version.» I know I’ve done this before.
5 Answers 5
On most Linux distributions you can use update-alternatives like this:
sudo update-alternatives --config java
It will list all packages that provide java command and will let you change it. If you don’t want to change it, simply Ctrl-C from it.
There is only one catch — if you installed some java not using official package manager ( dpkg / apt-get , rpm / yum ), but simply extracted it, update-alternatives will not show it.
@Xiao: unfortunately, not all versions of update-alternatives have —list option. e.g. Centos 6.7 doesn’t.
To find all files. The package manager with your version of Linux should also be able to list them.
«package manager» . Unless someone installed a java version manually. Find is a valid approach, though 🙂 find / -type f -name java -print 2>/dev/null | xargs -i echo <> -version | bash
@tink How would one use the find with xargs but add a blank line between each version result when there are multiple ‘java’ executables?
@LeeMeador find /usr -type f -name java -print 2>/dev/null | xargs -i echo <> -version | bash 2>&1 | sed ‘:a;N;$!ba;s/\n/\n\n/g’
I use this to list the Java installs available:
sudo update-alternatives --display java
I was previously using the following to determine the java 8 installation for an application that needed an environment variable set so it could use a java version that was not set as the default:
update-java-alternatives -l java-8-oracle
However, that stopped working today. The update-java-alternatives script/program is no longer installed on my Ubuntu 14.04 system. What’s installed now is alternatives .
What I use now to get a specific alternatives java path is:
alternatives —display java | grep priority | grep jdk-1.8
Then I can massage the result to get what I need for my app’s environment variable.
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.
Как удалить Java в Ubuntu
Java — это очень популярный язык программирования, разработанный в компании Sun Microsystems, ныне принадлежащей корпорации Oracle. Существует две реализации Java открытая и свободная OpenJDK и проприетарная Oracle Java.
Если вы захотите установить одну из них, а другая уже установлена, то первую придется удалить. В этой статье будет рассмотрено удаление Java в Ubuntu 20.04, а также будет показано как определять тип и версию Java установленной на устройстве.
Как удалить Java в Ubuntu 20.04
1. Как узнать тип Java
Перед удалением Java с компьютера сначала необходимо узнать какой тип Java установлен в системе. Если Java ставилась только для запуска приложений, скорее всего это будет JRE (Java Runtime Environment — содержит только окружение для запуска программ). Если Java устанавливалась для разработки ПО, то в данном случае будет одна из следующих версий — Open JDK (полностью открытая версия) или Oracle Java (проприетарная версия от Oracle с дополнительными возможностями и поддержкой).
2. Как узнать версию Java
Чтобы узнать какая версия Java установлена в системе, а также узнать какой тип установлен необходимо выполнить команду в терминале:
В данном примере в системе установлена Java с типом JRE и версией 11.0.13.
3. Как узнать способ установки Java
Иногда требуется определить способ установки Java. Чтобы узнать это, необходимо выполнить команду:
Если команда ничего не вернула значит в система установлена Java от Oracle. Чтобы это проверить необходимо выполнить команду:
Также из вывода команды можно узнать, установлен ли пакет из официального репозитория или же из стороннего репозитория. На скриншоте выше можно увидеть, что Java в системе установлен при помощи стороннего репозитория под названием linuxprising. Если в выводе команды имя репозитория не отображается, значит Java была установлена при помощи официального репозитория Ubuntu.
4. Удаление Java
Для удаления Java из Ubuntu необходимо использовать команду:
sudo apt purge oracle-java11*
Команда выше удалит версию Java от Oracle. Если в системе установлена бесплатная версия (OpenJDK) необходимо выполнить следующую команду:
Также вместо 11 версии необходимо подставить ту, которая установлена в системе.
Выводы
В этой статье было описано удаление Java в Ubuntu 20.04. Сама процедура удаления несложная и буквально выполняется при помощи одной команды. Надеюсь, информация из статьи была вам полезной.
Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.
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.