I know it's installed because when I type:
$java -version
I get:
OpenJDK Runtime Environment (IcedTea6 1.12.5) (6b27-1.12.5-0ubuntu0.12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
And when I type:
$locate jdk
I get:
/home/arturo/Documents/2012a/sys/java/jre/glnxa64/jre/lib/servicetag/jdk_header.png
/usr/share/app-install/desktop/openjdk-6-jre:openjdk-6-java.desktop
/usr/share/app-install/desktop/openjdk-7-jre:openjdk-7-java.desktop
/usr/share/app-install/icons/openjdk-6.png
/usr/share/app-install/icons/openjdk-7.png
What worries me about the first item in the list is that the 2012a folder is my MATLAB folder and not a standard 'usr/lib' folder. I'm really confused on where the JDK and JRE got installed, because I need to set the $JAVA_HOME path pointing to the folder. Where am I missing something?
WAY-1 : Updated for the shortest and easy way
Below command will give you the path, But it will only work if java command is working in other words if java path is configured.
readlink -f $(which java)
Read more at Where can I find the Java SDK in Linux?
WAY-2 (Better than WAY-1) : Below answer is still working and try it if above command is not working
for you.
You need to dig into symbolic links. Below is steps to get Java directory
Step 1:
$ whereis java
java: /usr/bin/java /etc/java /usr/share/java
That tells the command java resides in /usr/bin/java.
Dig again:
Step 2:
$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 2009-01-15 18:34 /usr/bin/java -> /etc/alternatives/java
So, now we know that /usr/bin/java is actually a symbolic link to /etc/alternatives/java.
Dig deeper using the same method above:
Step 3:
$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 31 2009-01-15 18:34 /etc/alternatives/java -> /usr/local/jre1.6.0_07/bin/java
So, thats the actual location of java: /usr/local/jre.....
You could still dig deeper to find other symbolic links.
Reference : where is java's home dir?
Please use this command:
readlink -f $(which java)
It works for me with Ubuntu gnome.
On my computer the result is:
/usr/lib/jvm/java-7-oracle/jre/bin/java
Regards.
In generally, java gets installed at /usr/lib/jvm . That is where my sun jdk is installed. check if it is same for open jdk also.
$whereis java
java: /usr/bin/java /usr/bin/X11/java /usr/share/java /usr/share/man/man1/java.1.gz
$cd /usr/bin
$ls -l java
lrwxrwxrwx 1 root root 22 Apr 15 2014 java -> /etc/alternatives/java
$ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 39 Apr 15 2014 /etc/alternatives/java -> /usr/lib/jvm/java-7-oracle/jre/bin/java
So,JDK's real location is /usr/lib/jvm/java-7-oracle/
Location of JRE in Ubuntu:
/usr/lib/jvm/java-7-oracle/jre
$ whereis java
java: /usr/bin/java /usr/lib/java /usr/bin/X11/java /usr/share/java /usr/share/man/man1/java.1.gz
On Ubuntu 14.04, it is in /usr/lib/jvm/default-java.
For me, on Ubuntu, the various versions of JDK were in /usr/lib/jvm.
I found the solution to this with path name:
/usr/lib/jvm/java-8-oracle
I'm on mint 18.1
I am using Ubuntu 18.04.1 LTS. In my case I had to open the file:
/home/[username]/netbeans-8.2/etc/netbeans.conf
And change the jdk location to:
netbeans_jdkhome="/opt/jdk/jdk1.8.0_152"
Then saved the file and re-run Netbeans. It worked for me.
you can simply write the following command in the terminal of your linux system and get the java path :- echo $JAVA_HOME
The easiest way to do so is by typing echo $JAVA_HOME on your terminal.
Related
My java --version gives:
openjdk 11.0.13 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.21.10)
OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.21.10, mixed mode, sharing)
But when I do: javac --version I get:
javac 17
whereis java gives:
java: /usr/bin/java /usr/share/java /opt/jdk-17/bin/java /usr/share/man/man1/java.1.gz
As far as I can remember I downloaded openjdk 17 from the official site and followed official documentation.
I usually work with maven projects and I just noticed this issue. Haven't created any problem so far. But I would like to resolve it. Is it possible to do so without removing java and reinstalling?
Update:
echo $PATH
/home/arnob/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/opt/jdk-17/bin:/home/arnob/sdks/flutter/bin:/opt/maven/bin:/home/arnob/.local/bin:/home/arnob/.pub-cache/bin:/usr/lib/postgres/13/bin
And
ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 Dec 19 00:58 /usr/bin/java -> /etc/alternatives/java
In your bashrc, for example, seems like you're adding /opt/jdk-17/bin to the PATH, but at the end, not before /usr/bin/, and you have Java 11 JRE installed separately, so it gets picked up first
You should fix this by reversing it
export JAVA_HOME=/opt/jdk-17
export PATH="${JAVA_HOME}/bin:$PATH"
I suggest doing the same thing for flutter, maven, Postgres, etc
Run the below commands in your terminal and choose the default java and javac version. You needn't uninstall anything.
update-alternatives --config java
update-alternatives --config javac
Ubuntu 16.04.1 LTS
I have installed java by sudo apt-get install default-jdk
$ java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~16.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
$ which java
/usr/bin/java
and in /home/hadoop/hadoop-3.3.1/etc/hadoop/hadoop-env.sh, I have added
export JAVA_HOME=/usr/bin/java
hadoop#ubuntu:~/hadoop$ bin/hadoop
ERROR: JAVA_HOME /usr/bin/java does not exist
anyone can help?
/usr/bin/java is not a java home. A java home must be a folder (not a program) with a bin directory which contains java, jps, maybe javac and so on. You must find your jre or jdk folder and set it as JAVA_HOME.
get ll /usr/bin/java and it may be a symbolic link to your Java path. or do find /usr/lib/jvm/java-1.x.x-openjdk to find your java home. The parent directory of Java program is your JAVA_HOME and must be set with export in hadoop-env.sh.
I could not run it with Java 11 installed so i installed Java 8 and tried this : /usr/lib/jvm/java-8-openjdk-amd64/jre/bin and it worked fine.
you could run readlink -f $(which java) command which returns the actual path to the target file.
This will give you an output like this
readlink -f $(which java)
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
I'm using RHEL8 which has default OpenJDK installed.
which java command points to /usr/bin/java.
java -version gives openjdk version "1.8.0_252"
Installed java in /u01/app/java/ location. Modified the .bashrc like below & sourced it.
export JAVA_HOME=/u01/app/java/jdk1.8.0_241/
PATH="$JAVA_HOME/bin/java:$HOME/.local/bin:$HOME/bin:$PATH"
export PATH
Now JAVA_HOME points to /u01/app/java/jdk1.8.0_241/ But which java or java -version still points to the OpenJDK.
Added the same in .bash_profile file & removed it from the .bashrc : Results are same
Deleted OpenJDK & made changes in .bash_profile. But by doing so ended up with "Command not found" error.
How can i fix it?
It was Path issue.
I have given PATH="$JAVA_HOME/bin/java:$HOME/.local/bin:$HOME/bin:$PATH" for PATH. which should not be the case.
Modified my PATH to below. It worked.
PATH="$JAVA_HOME/bin:$HOME/.local/bin:$HOME/bin:$PATH"
export PATH
That happens because when you invoke java it is actually invoked /usr/bin/java, which, issuing ls -l /usr/bin/java you will probably see is linked to the openjdk installation (probably through a double link: the first one being /usr/bin/java to /etc/alternatives/java and the second one being the link to the "real" java executable). For example, on my debian:
gianluca#asus-debian:~$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 mag 20 2018 /usr/bin/java -> /etc/alternatives/java
gianluca#asus-debian:~$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 43 nov 22 2019 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java
You can fix in two ways:
Dirty way, you manually update all the symbolic links in /usr/bin that lead to the unwanted java version and make them point to the desired one
Clean way, you use alternatives that does the job for you.
You can read more about alternatives for RHEL here (mid-page... "The longer version").
Good link
I'm trying ubuntu inside my mac docker environment for development. javac/gcc works fine, but when I try to use JNI to connect java and c program, I found a problem. I need to find the include file and libjvm.so file on my ubuntu docker image. But unfortunately I found the javac is actually:
root#4968756a1edd:~/mynet/mytest/build/jni# javac -version
javac 1.8.0_191
root#4968756a1edd:~/mynet/mytest/build/jni# ls -lrt `which javac`
lrwxrwxrwx 1 root root 23 Feb 6 07:38 /usr/bin/javac ->
/etc/alternatives/javac
Well, in an ubuntu/centos VM installation, usually there's a directory for a jdk and everything (bin/lib/include) is under this directory. But in docker image, how can I find this jdk installation location and all those headers/libraries?
In bash you can set env variables like this:
sudo -H gedit /etc/environment
JAVA_HOME=/path/to/java/folder
I'm attempting to compile my companies codebase using Maven which is wrapped in an Ant launcher for backwards compatibility reasons. I am running Oracle Linux 6.6, Java 1.7 u79-b14, Ant 1.7.1 and Maven 3.0.5 which are versions dictated to me by the enterprise infrastructure team.
When I set JAVA_HOME I get the following error when executing Ant Error: Could not find or load main class org.apache.tools.ant.launch.Launcher but if JAVA_HOME is commented out then Ant seems to run just fine.
#~/.bashrc
export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64
export MAVEN_HOME=/usr/share/maven
export M2_HOME=/usr/share/maven
export MAVEN_OPTS="-Xmx1024m"
export BUILD_CHROOT="/home/builduser/builds"
Included to help is the location at which Java is installed.
[builduser#iaas-a-jen03 ~]$ which java
/usr/bin/java
[builduser#iaas-a-jen03 ~]$ ls -la /usr/bin/java
lrwxrwxrwx 1 root root 22 Jun 30 11:58 /usr/bin/java -> /etc/alternatives/java
[builduser#iaas-a-jen03 ~]$ ls -la /etc/alternatives/java
lrwxrwxrwx 1 root root 46 Jun 30 11:58 /etc/alternatives/java -> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
The issue was resolved by following the steps found in this blog post... http://pkolomeitsev.blogspot.co.uk/2015/01/apache-ant-error-could-not-find-or-load.html
ant --execdebug was the key to creating the right folders. Then I just had to make sure that java-1.7.0-openjdk-devel.x86_46 was installed and voila!