Find java jre linux

Which JRE am I using?

There are two varieties of JRE available. Java VM: IBM vs. Sun. Is there a way to know which JRE I am using through JavaScript or some Java issued command.

10 Answers 10

The following command will tell you a lot of information about your java version, including the vendor:

java -XshowSettings:properties -version 

It works on Windows, Mac, and Linux.

I don’t know why people are not voting this one higher since it is the easiest to accomplish in windows and linux. Do you know if it works on Mac?

This command reports Oracle as my Java vendor in my Ubuntu system, despite it being OpenJDK actually.

@clapas could you please post the version of ubuntu that you are running and the command you used to install java? thanks

 System.out.println(System.getProperty("java.vendor")); System.out.println(System.getProperty("java.vendor.url")); System.out.println(System.getProperty("java.version")); Sun Microsystems Inc. http://java.sun.com/ 1.6.0_11 
  1. Open up your:
    • command prompt if you’re using Windows
    • terminal if you’re using mac or Linux
  2. Type in:
java -version // This will check your JRE version javac -version // This will check your Java compiler version if you installed the JDK 

If you need more info about the JVM you can call the executable with the parameter -XshowSettings:properties . It will show a lot of System Properties. These properties can also be accessed by means of the static method System.getProperty(String) in a Java class. As example this is an excerpt of some of the properties that can be obtained:

$ java -XshowSettings:properties -version [. ] java.specification.version = 1.7 java.vendor = Oracle Corporation java.vendor.url = http://java.oracle.com/ java.vendor.url.bug = http://bugreport.sun.com/bugreport/ java.version = 1.7.0_95 [. ] 

So if you need to access any of these properties from Java code you can use:

System.getProperty("java.specification.version"); System.getProperty("java.vendor"); System.getProperty("java.vendor.url"); System.getProperty("java.version"); 

Take into account that sometimes the vendor is not exposed as clear as Oracle or IBM. For example,

$ java version "1.6.0_22" Java(TM) SE Runtime Environment (build 1.6.0_22-b04) Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing) 

HotSpot is what Oracle calls their implementation of the JVM. Check this list if the vendor does not seem to be shown with -version .

java version «1.6.0_22» Java(TM) SE Runtime Environment (build 1.6.0_22-b04) Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

The Java system property System.getProperty(. ) to consult is «java.runtime.name» . This will distinguish between «OpenJDK Runtime Environment» and «Java(TM) SE Runtime Environment». They both have the same vendor — «Oracle Corporation».

This property is also included in the output for java -version .

 Version: java -version Location: where java (in Windows) which java (in Unix, Linux, and Mac) 

To set Java home in Windows:

Читайте также:  Расширить дисковое пространство linux

Right click on My computerPropertiesAdvanced system settingsEnvironment VariableSystem VariableNew. Give the name as JAVA_HOME and the value as (e.g.) c:\programfiles\jdk

Select Path and click Edit , and keep it in the beginning as: %JAVA_HOME%\bin; . remaining settings goes here

JAVA_HOME

Git Bash + Windows 10 + Software that came bundled with its own JRE copy:

Do a «Git Bash Here» in the jre/bin folder of the software you installed.

Then use «./java.exe -version» instead of «java -version» to get the information on the software’s copy rather than the copy referenced by your PATH environment variable.

Get the version of the software installation: ./java.exe -version

JMIM@DESKTOP-JUDCNDL MINGW64 /c/DEV/PROG/EYE_DB/INST/jre/bin $ ./java.exe -version java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode) 

Get the version in your PATH variable: java -version

JMIM@DESKTOP-JUDCNDL MINGW64 /c/DEV/PROG/EYE_DB/INST/jre/bin $ java -version java version "10" 2018-03-20 Java(TM) SE Runtime Environment 18.3 (build 10+46) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode) 

As for addressing the original question and getting vendor information:

./java.exe -XshowSettings:properties -version ## Software's copy java -XshowSettings:properties -version ## Copy in PATH 

Источник

How to find path where jdk installed?

I’ve installed jdk1.7.0.rpm package in RHEL6.
Where I do find the path to execute my first java program?

Hi, Mohammad. It’s not a stupid question, but one that has been answered in several places already — like this or this question.

Just an PS: on MacOS, Java is usually installed at ‘/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home’, where the version number could be different.

4 Answers 4

For your first java program read this tutorial:

Note these commands give different results. If you are interested in the non-symlink path use whereis java.

I don’t really think this answers the question. The java binary gets installed with the JRE, but if you’re doing development you need JDK, which isn’t necessarily installed in which java (which in my case is /usr/bin).

On RHEL7, you can use locate :

and it led me to the /usr/lib/jvm/ directory which contained the directories:

java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/ jre/ jre-1.8.0/ jre-1.8.0-openjdk/ jre-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/ jre-openjdk/ 

Each of these contain a bin/java

To find the full path of the symbolic link use:

This gave me mostly JDK6 even though java -version gave me 1.8. There was one link to the JDK8 folder near the top.

You can list the installed files with

You will see somewhere a bin directory with java executable

But if the JDK RPM was correctly installed you should already find java in you path.

javac MyFirstJavaClass.java 

and if everything compiles

(If you didn’t change anything the current directory . should already be in your class path)

Since this question is RPM specific, rpm is the way to get started (as answered by @Matteo).

-q is short for --query -l is short for --list 
rpm -ql jdk1.8.0_20 | grep "jdk1.8.0_20/bin$" 

Knowing this may be desirable for setting a user or application’s $JAVA_HOME variable. This is often needed when a system has multiple versions of java installed, or multiple distributions of java installed, such as OpenJDK and Oracle/Sun.

Читайте также:  Распаковать файл rar linux

$JAVA_HOME Example

In the ~/.bash_profile , or related file ( .bashrc , .zshrc , .cshrc , setenv.sh ), something similar to the below may be used.

JAVA_HOME='/usr/java/jdk1.8.0_20' export JAVA_HOME PATH="$JAVA_HOME/bin:$PATH" export PATH 

If you would like more control over where Java gets installed, such as in /opt , then the tarball can be used instead of the RPM file.

Other similar questions, are asking about how to find any binary or file, in the general case.

Источник

Install the Java Runtime Environment

The Java Runtime Environment (JRE) is required to run Java programs. Nowadays there are many JRE packages available from a variety of projects and companies, but the two most popular on Ubuntu are OpenJDK and Oracle HotSpot. Using one package over the other should not create any functional difference in most applications; however, some prefer OpenJDK over Oracle HotSpot as the former does not contain closed-source components, has a much clearer licensing and support policy, and is maintained as part of the Ubuntu archive, with easier installation and upgrades.

In this guide, we’ll be going through the installation of both JRE packages. Of course, you generally only need to pick the one that best suits your needs and preferences.

What you’ll learn

What you’ll need

That’s all you need. If you have that, let’s proceed to the next step!

2. Installing OpenJDK JRE

With new versions of Java released every 6 months, there are multiple versions available for use. Nowadays, Java 11 is the current Long Term Support (LTS) version, but Java 8 is still widely used. Moreover, the non LTS versions of Java are bringing a steady stream of innovation into the language, and also see some adoption.

Ubuntu offers the default-jre package, which is regularly updated to ship the latest version of the current OpenJDK JRE in Long Term Support (LTS). The default-jre is an excellent choice for most situations, thanks to the outstanding track of backwards compatibility of the Java Virtual Machine.

(Alternatively, you may opt to use a specific Java version, using for example the openjdk-11-jre package; as updates are released for that version of the Java Virtual Machine, that packages will be updated, allowing you to stick to the latest and greatest update of one specific version of the Java language.)

To install the OpenJDK JRE, we run:

sudo apt install default-jre 

We can check if OpenJDK JRE was properly installed by running:

It should output the following:

openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2) OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2, mixed mode) 

(Although the output may change in the future as new Java versions are promoted to LTS status, or the current LTS version receives updates.)

Читайте также:  Qt5 default astra linux

In the next step we’ll install Oracle HotSpot JRE.

3. Installing Oracle HotSpot JRE

Downloading the Oracle HotSpot JRE binaries

Download JRE binaries in .tar.gz (tarball) by heading over to their website. An Oracle account is needed to download the Oracle HotSpot JRE.

Oracle does not currently offer JRE packages for Java 11 or above from their website so, for this tutorial, we will use the Oracle HotSpot JRE version to be 8u291 (Java 8, update 291).

Installing

Create a directory to install JRE in with:

Move the JRE binaries into the directory:

sudo mv jre-8u291-linux-x64.tar.gz /usr/local/java 

Go into the install directory:

sudo tar zxvf jre-8u291-linux-x64.tar.gz 

Post-installation steps

To save space, delete the tarball by running:

sudo rm jre-8u291-linux-x64.tar.gz 

Let the system know where JRE is installed:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.8.0_291/bin/java" 1 

After that’s done, check the installation by running:

It should output the following:

java version "1.8.0_291" Java(TM) SE Runtime Environment (build 1.8.0_291-b10) Java HotSpot(TM) 64-Bit Server VM (build 25.291-b10, mixed mode) 

Need further assistance?

Источник

How to find my current JAVA_HOME in ubuntu?

To display JAVA_HOME variable path, type in terminal:

If nothing appears then set it with this:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 

This will differ according to your JDK type and version.

For displaying it again, follow the first command.

Follow JREs from different vendors on the same system, for using different JDK’s or switch between JDK’s.

It gives «/usr/lib/jvm/java-6-sun». But I have installed java 7. When I check it using «java -version» it gives java version «1.7.0_45» Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) Server VM (build 24.45-b08, mixed mode)

then execute second command for setting JAVA_HOME variable. NOTE: JAVA_HOME doesn’t make jdk default, it just makes JAVA_HOME variable set to a path & if you want to use different jdk installed on same machine then check my answer, I have edited it.

@Jax-L But now when I give echo JAVA_HOME it just displays as «JAVA_HOME». The path I gave is not displaying.

export works only until you restart. Or you add export to the .bashrc login script. But the correct way to set such environment variables is in /etc/environment

If you have JDK 1.6 (corresponding to Java 6) or a newer version installed, you should have a program named jrunscript in your PATH . You can use this to find the corresponding JAVA_HOME . Example:

$ jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));' /opt/local/jdk1.7.0_76/jre 

You could set the environment variable like this:

$ export JAVA_HOME="$(jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));')" 

Note that the JRE doesn’t include jrunscript , so this will only work if you install the JDK, not just the JRE.

Источник

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