# Cannot execute Julia 1.9.2 binary on NixOS

**URL:** <https://discourse.julialang.org/t/cannot-execute-julia-1-9-2-binary-on-nixos/102748>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 12, 2023, 4:33pm UTC](https://discourse.julialang.org/t/cannot-execute-julia-1-9-2-binary-on-nixos/102748 "2023-08-12T16:33:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![loonatick-src](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/loonatick-src/32/32248_2.png) [@loonatick-src](https://discourse.julialang.org/u/loonatick-src)\
**Post date:** [August 12, 2023, 4:33pm UTC](https://discourse.julialang.org/t/cannot-execute-julia-1-9-2-binary-on-nixos/102748/1 "2023-08-12T16:33:56Z")

</div>

([cross-posted from unix.stackexchange](https://unix.stackexchange.com/q/753458/440221))

This is most likely a NixOS-specific issue. I downloaded the [Julia 1.9.2 (Linux, x86-64, glibc) prebuilt binary](https://julialang.org/downloads/) and tried to execute the binary, but I get the following error.

`bash: ./julia: cannot execute: required file not found`

I am able to execute all other binaries on my machine. My understanding is that this is because bash cannot find the interpreter required for executing this file. In this case it should be a loader, I guess? Here’s the output of `file`,

```julia-auto
$ file julia
julia: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.4.0, with debug_info, not stripped

```

and `ldd`

```julia-auto
$ ldd julia
	linux-vdso.so.1 (0x00007ffdae587000)
	libdl.so.2 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libdl.so.2 (0x00007fe5955f4000)
	libpthread.so.0 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libpthread.so.0 (0x00007fe5955ef000)
	libc.so.6 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 (0x00007fe595409000)
	libjulia.so.1 => /home/chaitanyak/Downloads/julia-1.9.2/bin/./../lib/libjulia.so.1 (0x00007fe5953e6000)
	/lib64/ld-linux-x86-64.so.2 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib64/ld-linux-x86-64.so.2 (0x00007fe5955fb000)

```

I am using `NixOS 23.05.2573.61676e4dcfee (Stoat) x86_64`.

Verbose output of ldd

```julia-auto
$ ldd -v julia
	linux-vdso.so.1 (0x00007ffcd2942000)
	libdl.so.2 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libdl.so.2 (0x00007efd29f12000)
	libpthread.so.0 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libpthread.so.0 (0x00007efd29f0d000)
	libc.so.6 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 (0x00007efd29d27000)
	libjulia.so.1 => /home/chaitanyak/Downloads/julia-1.9.2/bin/./../lib/libjulia.so.1 (0x00007efd29d04000)
	/lib64/ld-linux-x86-64.so.2 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib64/ld-linux-x86-64.so.2 (0x00007efd29f19000)

	Version information:
	./julia:
		libc.so.6 (GLIBC_2.2.5) => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6
	/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libdl.so.2:
		libc.so.6 (GLIBC_ABI_DT_RELR) => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6
		libc.so.6 (GLIBC_2.2.5) => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6
	/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libpthread.so.0:
		libc.so.6 (GLIBC_ABI_DT_RELR) => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6
		libc.so.6 (GLIBC_2.2.5) => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6
	/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6:
		ld-linux-x86-64.so.2 (GLIBC_2.2.5) => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib64/ld-linux-x86-64.so.2
		ld-linux-x86-64.so.2 (GLIBC_2.3) => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib64/ld-linux-x86-64.so.2
		ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib64/ld-linux-x86-64.so.2
	/home/chaitanyak/Downloads/julia-1.9.2/bin/./../lib/libjulia.so.1:
		libdl.so.2 (GLIBC_2.3.3) => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libdl.so.2
		libdl.so.2 (GLIBC_2.2.5) => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libdl.so.2
		libpthread.so.0 (GLIBC_2.2.5) => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libpthread.so.0
		libc.so.6 (GLIBC_2.2.5) => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6

```

# Edit

I also tried using the possible interpreters directly.

```julia-auto
$ /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib64/ld-linux-x86-64.so.2 julia 
julia: error while loading shared libraries: julia: cannot open shared object file: No such file or directory

$ /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/ld-linux-x86-64.so.2 julia 
julia: error while loading shared libraries: julia: cannot open shared object file: No such file or directory

```

So, it looks like that it cannot open some `.so` file, but does not provide its name.

## Edit 2

I ran the interpreters under `gdb` and it gives some more information.

```julia-auto
(gdb) r Downloads/julia-1.9.2/bin/julia
Starting program: /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/ld-linux-x86-64.so.2 Downloads/julia-1.9.2/bin/julia
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libthread_db.so.1".
[Detaching after fork from child process 29527]
[New Thread 0x7ffff17ff6c0 (LWP 29528)]
ERROR: could not load library "/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/../lib/julia/sys.so"
/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/../lib/julia/sys.so: cannot open shared object file: No such file or directory
[Thread 0x7ffff7dae0c0 (LWP 29524) exited]
[Thread 0x7ffff17ff6c0 (LWP 29528) exited]
[New process 29524]
[Inferior 1 (process 29524) exited with code 01]
(gdb)

```

So, it seems that it is trying to locate `sys.so` that ships with Julia inside the nix store. So, is this a nix-specific problem? Is the only workaround to create a nix package for Julia 1.9?

# Edit 3

So, Julia ships with its own shared object files, and instead of searching for them there, the binary tries to search for them relative to some other location in my nix store. Is modifying RPATH of the julia binary using patchelf a solution to this?

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [August 12, 2023, 5:01pm UTC](https://discourse.julialang.org/t/cannot-execute-julia-1-9-2-binary-on-nixos/102748/2 "2023-08-12T17:01:06Z")

</div>

Julia 1.9 is in Nixpkgs, you can just use that one, or use the included Nix expression [https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/development/compilers/julia/1.9-bin.nix](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/development/compilers/julia/1.9-bin.nix)

---

<div class="post-metadata">

**Author:** ![loonatick-src](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/loonatick-src/32/32248_2.png) [@loonatick-src](https://discourse.julialang.org/u/loonatick-src)\
**Post date:** [August 12, 2023, 5:30pm UTC](https://discourse.julialang.org/t/cannot-execute-julia-1-9-2-binary-on-nixos/102748/3 "2023-08-12T17:30:36Z")

</div>

Aw man how did I miss this. Thank you.
