How to fetch Java version using single line command in Linux
- Redirect stderr to stdout.
- Get first line
Filter the version number.
java -version 2>&1 | head -n 1 | awk -F '"' '{print $2}'
Correct way to check Java version from BASH script
Perhaps something like:
if type -p java; then
echo found java executable in PATH
_java=java
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
echo found java executable in JAVA_HOME
_java="$JAVA_HOME/bin/java"
else
echo "no java"
fi
if [[ "$_java" ]]; then
version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
echo version "$version"
if [[ "$version" > "1.5" ]]; then
echo version is more than 1.5
else
echo version is less than 1.5
fi
fi
Running a Specific Version of Java on the Linux Command Line
Given this is not caused by a permissions issue, it could be the result of a missing 32 bit runtime which is detailed here
How to run an application on a specific Java version?
You can run java
with the absolute path to the installation
This would be your default /usr/bin/java
installation
java -version
To change it, use the absolute path
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -version
If you're not running the java
command directly, try setting the JAVA_HOME variable:
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/" pdfsam
How to check java version at linux (RedHat6)
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.
Related Topics
About Process Control Block in Os
Executing String Sent from One Terminal in Another in Linux Pseudo-Terminal
Difference Between Cgroups and Namespaces
How to Install Packages in Linux (Centos) Without Root User with Automatic Dependency Handling
Check Whether a Certain File Type/Extension Exists in Directory
In Screen, How to Send a Command to All Virtual Terminal Windows Within a Single Screen Session
Linux Script with Curl to Check Webservice Is Up
In Linux, What Do All the Values in the "Top" Command Mean
Unix Command to List Files Containing String But *Not* Containing Another String
Find File Then Cd to That Directory in Linux
Gcc Verbose Mode Output Explanation
Maximum Number of Inodes in a Directory
Linux Makefile Structure and Documentation