Which jdk is installed linux

Where can I find the Java SDK in Linux after installing it?

I installed JDK using apt-get install but I don’t know where my jdk folder is. I need to set the path for that. Does any one have a clue on the location?

14 Answers 14

This depends a bit from your package system . if the java command works, you can type readlink -f $(which java) to find the location of the java command. On the OpenSUSE system I’m on now it returns /usr/lib64/jvm/java-1.6.0-openjdk-1.6.0/jre/bin/java (but this is not a system which uses apt-get ).

On Ubuntu, it looks like it is in /usr/lib/jvm/java-6-openjdk/ for OpenJDK, and in some other subdirectory of /usr/lib/jvm/ for Suns JDK (and other implementations as well, I think).

For any given package you can determine what files it installs and where it installs them by querying dpkg. For example for the package ‘openjdk-6-jdk’: dpkg -L openjdk-6-jdk

I think readlink as given is most elegant (and efficient), but I suggest readlink -f $(which javac) — note the ‘c’ in case there is a strange mix of JDK and JRE on the same machine. The JDK includes a compiler (javac) and a JRE does not. However if path is not correct, which will fail and you can try this: find /usr/java -wholename ‘*ava/jdk*’ -prune as I note in a comment below.

will tell you which java implementation is the default for your system and where in the filesystem it is installed. Check the manual for more options.

@dequis, it’s an answer specific to debian, since the question mentioned apt-get and the distro to be Debian 2.6.26 . AFAIK, it should be the same for all debian derivatives.

should give you something like

This does not actually point to a full JDK. 1. It is a symlink, and even if you read the symlink, the binary is also not within a JDK. For example, if I run the command readlink -f $(which javac) it prints /usr/lib/jvm/java-8-oracle/bin/javac . That bin folder is NOT a JDK. General acid-base test to see if its a JDK is to see if the current $JAVA_HOME contains a path of lib/tools.jar . In the cast of /usr/lib/jvm/java-8-oracle/bin that is not true, therefore it is not a JDK.

On Centos / RHL This is what I prefer to find the JDK (if installed) find /usr/java -wholename ‘*ava/jdk*’ -prune But behavior depends whether you are talking about OpenJDK or Oracle Java and how it was installed in the first place.

This question will get moved but you can do the following

«find / -name ‘javac'» is less typing, but requires admin (root) privilege or you will get a lot permission denied messages.

Use find to located it. It should be under /usr somewhere:

When running the command, if there are too many «Permission denied» message obfuscating the actual found results then, simply redirect stderr to /dev/null

find /usr -name java 2> /dev/null 

Another best way to find Java folder path is to use alternatives command in Fedora Linux (I know its for Ubuntu but I hit this post from google just by its headline). Just want to share incase people like me looking for answers for fedora flavour.

Читайте также:  Linux dhcp client config

To display all information regarding java

alternatives --display java 

Three Step Process: First: open Terminal-> $ whereis java it would give output like this: java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz

Second: ls -l /usr/bin/java It would give output like this: lrwxrwxrwx 1 root root 22 Feb 9 10:59 /usr/bin/java -> /etc/alternatives/java

Third: ls -l /etc/alternatives/java output is the JDK path: lrwxrwxrwx 1 root root 46 Feb 9 10:59 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

It’s /usr/local/java/jdk[version]

This question still seems relevant, and the answer seems to be a moving target.

On my debian system (buster):

> update-java-alternatives -l java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64 

However, if you actually go look there, you’ll see there are multiple directories and symbolic links placed there by the package system to simplify future maintenance.

The actual directory is java-11-openjdk-amd64 , with another symlink of default-java . There is also an openjdk-11 directory, but it appears to only contain a source.zip file.

Given this, for Debian ONLY, I would guess the best value to use is /usr/lib/jvm/default-java , as this should always be valid, even if you decide to install a totally different version of java, or even switch vendors.

The normal reason to want to know the path is because some application wants it, and you probably don’t want that app to break because you did an upgrade that changed version numbers.

Источник

How to tell if JRE or JDK is installed

I have one computer that I intentionally installed JDK on. I have another computer with JRE, for, among other things, testing. However, when I got a java application working on this computer, and then tried it on another, it complained that JDK was required. How can I check if JDK was somehow installed on my system? Note: the computer in question is a Mac.

Can you post the full text of the error, including how you’re trying to run it? You don’t need the JDK to run a Java program, just the JRE.

It was a friends computer- something about installing command line tools. I’ll comment again when I get a chance to inspect it again.

It sounds like you might be talking about making sure that Java is on your path, but that’s just a guess. Either way, you only need the JRE to run Java programs. You need the JDK to compile them.

Only few java programs need a JDK, IDEs, servlet containers like tomcat to compile JSPs and some others. What kind of application has the problem?

6 Answers 6

You can open up terminal and simply type

java -version // this will check your jre version javac -version // this will check your java compiler version if you installed 

this should show you the version of java installed on the system (assuming that you have set the path of the java in system environment).

Читайте также:  Astra linux network manager pptp

And if you haven’t, add it via

export JAVA_HOME=/path/to/java/jdk1.x 

and if you unsure if you have java at all on your system just use find in terminal

@Pacerier Why ?? i do not know that for sure lol!. Maybe you do not have JDK installed ? Running windows or linux ??

Normally a jdk installation has javac in the environment path variables . so if you check for javac in the path, that’s pretty much a good indicator that you have a jdk installed.

I realize that the OP was asking about a Mac, so it may be different there. But as for Windows, this test does not seem reliable. I just checked, and I do NOT have javac in my path, but I DO have a jdk installed. (In my case, my JAVA_HOME is pointed to C:\Program Files\Java\jdk1.8.0_45 )

@maciej-cygan described the process well, however in order to find your java path:

it gives you the path of java binary file which is a linked file in /usr/bin directory. next:

$ cd /usr/bin/ && ls -la | grep java

find the pointed location which is something as follows (for me):

enter image description here

then cd to the pointed directory to find the real home directory for Java. next:

which is as follows in this case:

enter image description here

so as it’s obvious in the screenshot, my Java home directory is /usr/lib/jvm/java-11-openjdk-amd64 . So accordingly I need to add JAVA_HOME to my bash profile ( .bashrc , .bash_profile , etc. depending on your OS) like below:

A generic, pure Java solution..

For Windows and MacOS, the following can be inferred (most of the time).

public static boolean isJDK() < String path = System.getProperty("sun.boot.library.path"); if(path != null && path.contains("jdk")) < return true; >return false; > 

However. on Linux this isn’t as reliable. For example.

  • Many JREs on Linux contain openjdk the path
  • There’s no guarantee that the JRE doesn’t also contain a JDK.

So a more fail-safe approach is to check for the existence of the javac executable.

public static boolean isJDK() < String path = System.getProperty("sun.boot.library.path"); if(path != null) < String javacPath = ""; if(path.endsWith(File.separator + "bin")) < javacPath = path; >else < int libIndex = path.lastIndexOf(File.separator + "lib"); if(libIndex >0) < javacPath = path.substring(0, libIndex) + File.separator + "bin"; >> if(!javacPath.isEmpty()) < return new File(javacPath, "javac").exists() || new File(javacPath, "javac.exe").exists(); >> return false; > 

Warning: This will still fail for JRE + JDK combos which report the JRE’s sun.boot.library.path identically between the JRE and the JDK. For example, Fedora’s JDK will fail (or pass depending on how you look at it) when the above code is run. See unit tests below for more info.

# Unix java -XshowSettings:properties -version 2>&1|grep "sun.boot.library.path" # Windows java -XshowSettings:properties -version 2>&1|find "sun.boot.library.path" 
 # PASS: MacOS AdoptOpenJDK JDK11 /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib # PASS: Windows Oracle JDK12 c:\Program Files\Java\jdk-12.0.2\bin # PASS: Windows Oracle JRE8 C:\Program Files\Java\jre1.8.0_181\bin # PASS: Windows Oracle JDK8 C:\Program Files\Java\jdk1.8.0_181\bin # PASS: Ubuntu AdoptOpenJDK JDK11 /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/lib # PASS: Ubuntu Oracle JDK11 /usr/lib/jvm/java-11-oracle/lib # PASS: Fedora OpenJDK JDK8 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.fc24.x86_64/jre/lib/amd64 #### FAIL: Fedora OpenJDK JDK8 /usr/java/jdk1.8.0_231-amd64/jre/lib/amd64 

Источник

Читайте также:  Linux add admin user

How can I tell what version of Java I have installed?

I want to start toying around with java (eventually getting to the point where I can write basic little programs for android or web), but I’ve managed to have java messed up on my computer (from past experiments). I’m not sure which version of java I have, and would like to know if there is a command to see the version of java that is installed and active. Also, which version works best? All this on 32bit Ubuntu 12.04 EDIT:
Ok, so it seems like I have both openjdk 6 and 7, with openjdk 7 in use. I want to use openjdk 7, so how do I uninstall openjdk 6? Is just via USC good enough or is there a command that should be run?

4 Answers 4

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:

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.

Источник

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