Which java command in linux

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’

Читайте также:  Linux proxy как установить

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 find which version of Java in Java installed folder?

A version of java is installed on my Linux machine. When i try this: root@test$: javac -version It given the result as: javac jdk1.7.0_80. Now my problem is i don’t know where that(1.7.0_80) java folder is. I have a folder named «java-7-oracle» in usr/lib/jvm. I am suspecting that it would be the folder for the installed version of java. Now I have a java folder and I want to know which version of java it is? How??

3 Answers 3

I think you can track all this by checking to where your java binaries linked to.

 #which javac /usr/bin/javac #ls -ln /usr/bin/java lrwxrwxrwx. 1 0 0 22 Nov 27 04:54 /usr/bin/java -> /etc/alternatives/java #ls -ln /usr/bin/javac lrwxrwxrwx. 1 0 0 23 Nov 27 04:54 /usr/bin/javac -> /etc/alternatives/javac # ls -ln /usr/bin/javadoc lrwxrwxrwx. 1 0 0 25 Nov 27 04:54 /usr/bin/javadoc -> /etc/alternatives/javadoc 
#ls -ld /etc/alternatives/java lrwxrwxrwx. 1 root root 46 Nov 27 04:54 /etc/alternatives/java -> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java 

therefore , my java installation is:

 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64 

I suppose you can track any binary like this.

Finding out which binary is executed when you type only the name is done using which , and using readlink you can condense the process to a single line.

Читайте также:  Проверка всех сетевых интерфейсов linux

readlink -e prints the value of a symbolic link or canonical file name, and the -e ensures it follows every component recursively.

tony@trinity:~$ readlink -e $(which java) /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java 

note: I don’t have javac installed on the machine I tested this on, so just used java, but the above will work work for any binary.

You also appear to be asking to find out which version of java is in a specific folder? For that you just do this,

which prevents Linux from search the path and finding the java binary directly. In your case,

/usr/lib/jvm/java-7-oracle/javac -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.

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.

Читайте также:  Настройка терминала linux ubuntu

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.

Источник

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