Error: command failed: 'cargo': No such file or directory (os error 2)

I’m currently traveling with a low-cost low-power machine (a ~2013 Acer C720 Chromebook that I just love).

I would like to be able to have a system-wide rust / cargo installation that I can use to write quick stdlib-only scripts without having to enter a nix shell. The same principle works fine for python and go, but for some reason I get an error trying to use rust, even though I have rustc and cargo in my system packages:

$ cargo new foo
error: command failed: 'cargo': No such file or directory (os error 2)
$ type -p cargo rustc
/run/current-system/sw/bin/cargo
/run/current-system/sw/bin/rustc
$ ldd $(type -p cargo) $(type -p rustc)
/run/current-system/sw/bin/cargo:
        linux-vdso.so.1 (0x00007f286cf56000)
        libc.so.6 => /nix/store/q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66/lib/libc.so.6 (0x00007f286cc00000)
        /nix/store/q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66/lib/ld-linux-x86-64.so.2 => /nix/store/q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66/lib64/ld-linux-x86-64.so.2 (0x00007f286cf58000)
/run/current-system/sw/bin/rustc:
        linux-vdso.so.1 (0x00007fdf66af5000)
        libc.so.6 => /nix/store/q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66/lib/libc.so.6 (0x00007fdf66800000)
        /nix/store/q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66/lib/ld-linux-x86-64.so.2 => /nix/store/q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66/lib64/ld-linux-x86-64.so.2 (0x00007fdf66af7000)

Is there any reason this shouldn’t work? Thanks for any suggestions!

(Things work fine in both nix-shell and nix shell as long as I have both cargo and rustc included in the shell, I’m just curious as to what is missing here.)

Very silly mistake (though a better error message would have helped) – I must have cleaned up a few large files (on this underpowered machine) and deleted something rustup needed.

Strace pointed me in the right direction – rustup default stable and rustup update and the error is now gone.

1 Like