How to check Oracle Java version if multiple versions of Java installed on Ubuntu

后端 未结 5 1358
感情败类
感情败类 2021-02-07 10:46

I have both OpenJDK and Oracle Java installed on my Ubuntu. If the activated java is OpenJDK, is there a way to check the version of Oracle java in bash shell

相关标签:
5条回答
  • 2021-02-07 11:13

    yes, you need to know the install path of the oracle one. then /path/to/there/bin/java -version. Assume that the openjdk one is your default java.

    0 讨论(0)
  • 2021-02-07 11:26

    you should follow bellow two commands

    1. sudo update-alternatives --config java

    In their show the all already installed Java versions like below

    2.gedit ~/.bashrc

    `export JAVA_HOME=/path/to/jdk/folder

    usually /usr/java/jdk or /usr/lib/java/jdk

    export PATH=$PATH:$JAVA_HOME/bin`

    add to bash

    0 讨论(0)
  • 2021-02-07 11:31

    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

    0 讨论(0)
  • 2021-02-07 11:32

    Go to the installation folder of the oracle Java, and then open the bin folder. Now open a terminal "here" and type java -version

    alternativelly,

    paste the entire path to that bin folder in the command line followed by java -version i.e. /path/to/bin/java -version

    0 讨论(0)
  • 2021-02-07 11:36

    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

    0 讨论(0)
提交回复
热议问题