20

I just ran the script below and it fetches and unpacks the JDK into the correct location. Problem is that every java command (as copied to /urs/bin) gives errors. I then double check by going into the JDK install directory by means of cd (I am now in JDK/bin) and type : ./java -version and get : ./java: No such file or directory, but java is there! ls -l on the JDK shows that all java clients are inside the bin.

#!/bin/bash
#Author: Yucca Nel http://thejarbar.org
#Will restart system
#Modify these variables as needed...
tempWork=/tmp/work
locBin=/usr/local/bin
javaUsrLib=/usr/lib/jvm

sudo mkdir -p $javaUsrLib
mkdir -p $tempWork
cd $tempWork

#Update this line to reflect newer versions of JDK...
wget http://download.oracle.com/otn-pub/java/jdk/7u2-b13/jdk-7u2-linux-i586.tar.gz

#Extract the download
tar -zxvf $tempWork/*

#Move it to where it can be found...

sudo mv -f $tempWork/jdk1.7* $javaUsrLib/

sudo ln -f -s $javaUsrLib/jdk1.7*/bin/* /usr/bin/
sudo rm -rf $tempWork
#Update this line to reflect newer versions of JDK...
export JAVA_HOME="$javaUsrLib/jdk1.7.0_02"

if ! grep "JAVA_HOME=$javaUsrLib/jdk1.7.0_02" /etc/environment
then
    echo "JAVA_HOME=$javaUsrLib/jdk1.7.0_02"| sudo tee -a /etc/environment
fi

sudo /sbin/reboot

exit 0

Running ls -l /usr/lib/jvm/jdk1.7.0_02/bin/java gives me : yucca@yucca-VirtualBox:~$ -rwxr-xr-x 1 yucca yucca 5654 2011-11-17 22:38 /usr/lib/jvm/jdk1.7.0_02/bin/java

also ran: file /usr/lib/jvm/jdk1.7.0_02/bin with an output of :

/usr/lib/jvm/jdk1.7.0_02/bin: directory
P̲̳x͓L̳
  • 3,615
  • 3
  • 29
  • 37
thejartender
  • 9,339
  • 6
  • 34
  • 51

2 Answers2

41

You're running on a 64bit system without a 32bit runtime environment.

Assuming ubuntu/debian issue:

apt-get install libc6-i386

Or you should install the 64bit version of the package into this VM (which is probably the best solution).

The error message is coming from the run-time linker/loader. if you do a readelf -l java you will find a line like:

 [Requesting program interpreter: /lib/ld-linux.so.2]

Which is what you expect for a 32bit application, and you probably don't have the 32bit environment installed - check with an ls -l of that program interpreter.

and example for a 64bit program would look like (your system may vary):

 [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]

If this is not the case, and you do have the 32bit libc installed, you can try an ldd java, which will give a listing like:

linux-gate.so.1 =>  (0xf76ef000)
libpthread.so.0 => /lib32/libpthread.so.0 (0xf76b3000)
libjli.so => /home/bubba/java/jdk1.7.0_02/bin/./../jre/lib/i386/jli/libjli.so (0xf769f000)
libdl.so.2 => /lib32/libdl.so.2 (0xf7699000)
libc.so.6 => /lib32/libc.so.6 (0xf751f000)
/lib/ld-linux.so.2 (0xf76f0000)

if there are lines saying not found then you should add pagkages providing that, but as you can see from this ldd all the dependencies are core libraries that should be present on practically all linux systems.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • Thank you. This is what happened... I am in the process of doing a set of tutorials showing how I set up my development environment. I now noticed that the version I am using of Ubuntu in VirtualBox was AMD 64 bit and I am on Intel chip. Prior to this the script worked, but I notice the new guest I did yesterday is from the wrong Ubuntu image. – thejartender Jan 31 '12 at 16:53
  • I had the same problem as the OP and it was solved by running `apt-get install libc6-i386`. I wonder if there may be additional issues with 32-bit JDK 7 on 64 bit Ubuntu? – Andrei Botalov Oct 28 '12 at 11:47
  • 1
    @Petesh having the same problem, but with an arm cpu. I wonder if there are libs for arm.. – Eugene Aug 15 '13 at 13:07
  • 1
    @Eugene You're on a Linux ARM platform? What does `file java` report? What does `readelf -l java | grep interp` report? Does that interpreter exist? Android uses a different interpreter `/system/bin/linker`, and if you're on Android then I don't know of a compiled JDK for Android. – Anya Shenanigans Aug 15 '13 at 15:16
  • @Petesh not yet android. But jdk 7 works fine. All I had to do is a sudo apt-get install libc6-* (around 40MB) – Eugene Aug 15 '13 at 17:04
  • Doesn't work on aarch64 (ARMv8). I wonder what the solution is for that architecture? – Alex Shroyer Jul 09 '17 at 12:42
  • @hoosierEE did you download the ARM64 version of the jdk? That would be an easier approach - there is an arm64 version of the Oracle JDK. – Anya Shenanigans Jul 09 '17 at 13:59
  • @Petesh That's what I tried. The only JRE I got to work was openjdk. Oracle java8 sitting right in front of me, `readelf -l java` looks fine, yet `java -version` gives "file not found". – Alex Shroyer Jul 09 '17 at 19:35
  • @hoosierEE it's not really practical to try to solve the issue over comments; but this 'file not found' is because the run-time interpreter just isn't there. What does `file $(readelf -l /usr/bin/java | sed -n 's/.*interpreter: \([^]]*\)\]/\1/p')` yield (this extracts the run-time interpreter and runs file on it)? Different ARM platforms have different run-time interpreters - I believe the Oracle one is looking for `/lib/ld-linux-armhf.so.3`. – Anya Shenanigans Jul 10 '17 at 07:42
6

I was getting the

bash: /usr/bin/java: No such file or directory

The issue was I installed the i586 version of Java on a x86_64 Debian.

The fix: I removed it and install the x64 version of Java. Everything is working fine now.

Peter Tretyakov
  • 3,380
  • 6
  • 38
  • 54
SPLUS1
  • 61
  • 1
  • 3