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.
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.
You could do:
find / -name java
To find all files. The package manager with your version of Linux should also be able to list them.
update-java-alternatives -l will list all the java versions installed via the alternatives system.
For instance on one of my systems it will display the version and the path:
java-1.6.0-openjdk-amd64 1061 /usr/lib/jvm/java-1.6.0-openjdk-amd64
java-7-oracle 1069 /usr/lib/jvm/java-7-oracle
If you want the oracle one then I guess you could do:
update-java-alternatives -l | grep oracle | awk '{ print $1 }'
This would alternatively find all oracle versions and issue the -version command against each one in the list:
update-java-alternatives -l | grep oracle | awk '{system($3"/bin/java -version")}'
Output may look something like this:
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
One step further would be to parse out the java version from the -version command and simply display it:
(update-java-alternatives -l | grep oracle | awk '{system(""$3"/bin/java -version 2>&1 | grep \"java version\"")}') | awk -F\" '{print $2}'
The 2>&1 is needed because Java will display version to standard error. The output would simply look like this (and could be easily assigned to a bash variable if you needed it that way):
1.7.0_67
If you had multiple oracle instances this would display the version for each one. If you wanted to find all the versions for every Java you could simply remove the | grep oracle
If you are using the openjdk java, then the oracle Java in your PC is just a folder. There is no command to check the version of that if you are not using it.
If you once used oracle java then it must be in your java alternatives and you can find the folder (usually with version in name) with:
update-alternatives --config java
If it says something like /usr/lib/jvm/jdk1.8.0_05/bin/java, then you have 1.8 in your pc.
If you haven't used oracle java anytime you simply have to check what you have downloaded.
If you want to simply see the version you are using:
java -version
Hope it helps
Videos
Does `java -version` show the JDK or the JRE?
How do I check the Java version inside a shell script?
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.
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:
file `which java javac`
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.
If your java version more than 1.6 then it should work
java -version
if version is not installed it returns error message
Please share some snapshot so i can rectify it
To answer your question directly, you can use
rpm -qi java
OR
yum info "java"
For future Referenecs . You can try any of these commands.
rpm -qi "package_name_without_quotes"
It gives information of installed package. To display information about one or more packages (glob expressions are valid here as well), use the following command :
yum info "package_name_without quotes"
OR
yum list "package_name_without_quotes"
OR
yum --showduplicates list "package_name_without_quotes"
The yum info package_name command is similar to the rpm -q --info package_name command, but provides as additional information the ID of the Yum repository the RPM package is found in.
You can also query the Yum database for alternative and useful information about a package by using the following command :
yumdb info "package_name_without_quotes"
This command provides additional information about a package, including the check sum of the package (and algorithm used to produce it, such as SHA-256), the command given on the command line that was invoked to install the package (if any), and the reason that the package is installed on the system.
I have a Java installation and I have only access via bash. How can I check the Java version from command line.
This should work. This assumes it’s installed in a directory that’s included in $PATH which isn’t always the case with Java. Some programs ship with their own version of Java specific to their application so you’ll first have to determine where it’s installed.
java --version
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
and finally:
#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.
readlink -e $(which java)
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,
/full/path/java -version
which prevents Linux from search the path and finding the java binary directly. In your case,
/usr/lib/jvm/java-7-oracle/javac -version