I tried to install the current oracle jre on a VM running NixOS.

Now the following happens:

[michas@cc:~]$ tar xvzf jre-7u40-linux-x64.tar.gz |grep bin/java

[michas@cc:~]$ ls -l ./jre1.7.0_40/bin/java
-rwxr-xr-x 1 michas nogroup 7750 Aug 27 09:17 ./jre1.7.0_40/bin/java

[michas@cc:~]$ ./jre1.7.0_40/bin/java
bash: ./jre1.7.0_40/bin/java: No such file or directory

WTF? The named file is obviously there. What is going on?

Trying to analyse further:

[michas@cc:~]$ strace ./jre1.7.0_40/bin/java
execve("./jre1.7.0_40/bin/java", ["./jre1.7.0_40/bin/java"], [/* 53 vars */]) = -1 ENOENT (No such file or directory)
write(2, "strace: exec: No such file or di"..., 40strace: exec: No such file or directory
) = 40
exit_group(1)                           = ?
+++ exited with 1 +++

[michas@cc:~]$ strace ./jre1.7.0_40/bin/jav
strace: Can't stat './jre1.7.0_40/bin/jav': No such file or directory

Ok, the output of a really missing file looks different.

[michas@cc:~]$ file ./jre1.7.0_40/bin/java
./jre1.7.0_40/bin/java: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, BuildID[sha1]=a558f547fe0b95fdc6a109cb7d9692d6d7969794, not stripped

[michas@cc:~]$ file ~/t
/home/michas/t: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, not stripped

The latter is a tiny self compiled binary running without problems. Both look very similar. Hence format the binary itself seems to be fine.

[michas@cc:~]$ ldd ./jre1.7.0_40/bin/java
/run/current-system/sw/bin/ldd: line 116: ./jre1.7.0_40/bin/java: No such file or directory

Seems like there is a problem regarding the needed shared libraries.

What is going on and how can I fix it?


You can't usually run binary files in NixOS, they will either need some environment variables set or to be patched with patchElf. I assume you can install and run java using the nix package manager. You can probably also create a suitable environment to run it using myEnvFun.

  • 2
    Perhaps, an example of using patchelf to run a binary in a nix environment can be of some use to those searching a solution. But that case is the user's "active" nix environment in a single-user nix installation under CentOS, yours needs may be different (IIC the more nixy approach would be to refer not to the "active" symlinked environment, but rather to a specific versioned, hashed one in the nix store). – imz -- Ivan Zakharyaschev Apr 7 '15 at 8:15

It looks like nixos has a package for oracle jre7.

If you want to make a custom nix expression to install jre or jdk then it might be a good idea to look at the existing nix expression for jdk7/jre7.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.