No such file or directory (os error 2) cargo or rust run

Good everyone, I am installing magic mirror, I would like to install spotify and for that I need the librespot library, librespot needs rust to work, but I always get the error "No such file or directory (os error 2) ". I've searched the forum but I haven't seen anything. I don't understand much either, I'm a newbie. OS: Raspbian 11 32bits.

[package]
name = "librespot"
version = "0.4.2"
authors = ["Librespot Org"]
license = "MIT"
description = "An open source client library for Spotify, with support for Spotify Connect"
keywords = ["spotify"]
repository = "https://github.com/librespot-org/librespot"
readme = "README.md"
edition = "2018"

[workspace]

[lib]
name = "librespot"
path = "src/lib.rs"

...

You're going to need to include the error message and the command you ran.

1 Like

Error message:

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

Command (no matter the command, they all fail):

cargo build --release
cargo install librespot
...

Sanity check: you installed the Rust toolchain like described here? Is there a ~/.cargo/bin/ folder on your machine containing the cargo executable? If so, have you added the folder to the PATH environment variable?

Yes, I have the "cargo" folder with the executable, it is also added in the PATH.

pruden@raspberrypi:~/.cargo $ echo $PATH
/home/pruden/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
pruden@raspberrypi:~ $ ls .cargo/bin/
cargo         cargo-miri     rust-analyzer  rustfmt      rust-lldb
cargo-clippy  clippy-driver  rustc          rust-gdb     rustup
cargo-fmt     rls            rustdoc        rust-gdbgui

When I do an update I also get this error:

pruden@raspberrypi:~ $ rustup update
info: syncing channel updates for 'stable-aarch64-unknown-linux-gnu'
info: checking for self-update

  stable-aarch64-unknown-linux-gnu unchanged - ***(error reading rustc version)***

info: cleaning up downloads & tmp directories

Hmm, maybe you have a second version of Rust installed from a package of your OS? What does it say when your run:

> whereis rustup
> whereis rustc
> whereis cargo

?

pruden@raspberrypi:~ $ whereis rustup
rustup: /home/pruden/.cargo/bin/rustup
pruden@raspberrypi:~ $ whereis rustc
rustc: /home/pruden/.cargo/bin/rustc
pruden@raspberrypi:~ $ whereis cargo
cargo: /usr/share/cargo /home/pruden/.cargo/bin/cargo

This does not look good. What is it? Is it a different version of Cargo or a different program that happens to also be named Cargo? Either way, I assume that binary is causing you issues when you try to execute cargo build or any other subcommand.

I don't know what it is, I needed to charge for librespot, I think it was installed automatically when installing librespot? To install it you run a script, maybe you are downloading it there?

pruden@raspberrypi:~ $ ls /usr/share/cargo/registry/*
/usr/share/cargo/registry/alsa-sys-0.2.0:
build.rs  Cargo.toml  LICENSE  README.md  src

/usr/share/cargo/registry/libc-0.2.80:
build.rs  Cargo.toml  CONTRIBUTING.md  LICENSE-APACHE  LICENSE-MIT  README.md  rustfmt.toml  src  tests  triagebot.toml

/usr/share/cargo/registry/pkg-config-0.3.18:
Cargo.toml  CHANGELOG.md  debian  LICENSE-APACHE  LICENSE-MIT  README.md  src  tests

Weird. I don't know where this is coming from but it looks fishy to me. I'm a little bit out of my depth here and I don't want to recommend just deleting it and breaking something on your machine :sweat_smile:

Maybe if your run ~/.cargo/bin/cargo build --release, it will work?

Same mistake... I am so confused...

pruden@raspberrypi:~ $ .cargo/bin/cargo build --release
error: command failed: 'cargo': No such file or directory (os error 2)

The other reason you can get “No such file or directory” for an executable that clearly exists is when the error is for a dynamically linked library instead. Cargo doesn’t have any unusual dependencies, but you could try

ldd .cargo/bin/cargo

and see if it's successful or not.

pruden@raspberrypi:~ $ ldd .cargo/bin/cargo
	/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so => /usr/lib/arm-linux-gnueabihf/libarmmem-v8l.so (0xf7170000)
	libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xf7130000)
	librt.so.1 => /lib/arm-linux-gnueabihf/librt.so.1 (0xf7118000)
	libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xf70ec000)
	libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xf707d000)
	libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xf7069000)
	libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xf6f15000)
	/lib/ld-linux-armhf.so.3 (0xf794a000)

I have uninstalled the rust program and deleted all its files. I have reinstalled it but it still gives the same error :smiling_face_with_tear: :melting_face:.

I notice you said you’re using 32-bit Raspbian, but the rustup output you included says

info: syncing channel updates for 'stable-aarch64-unknown-linux-gnu'

which is obviously for 64-bit ARM. I would expect this to be either arm-unknown-linux-gnueabihf or armv7-unknown-linux-gnueabihf. I don’t know about the error message, but this can’t be helping.

I believe the commands to install a different toolchain for ARM would be:

rustup toolchain install stable-arm-unknown-linux-gnueabihf
rustup default stable-arm-unknown-linux-gnueabihf
6 Likes

That was the problem, I was using the wrong version, I don't understand why I was downloading that version, now everything works correctly.

Thank you all for the help! ^-^

Thanks man

I had to use this
armv7-unknown-linux-gnueabihf

For future users
Visit: Platform Support - The rustc book

1 Like

Updating rustup also helped me with the issue.

rustup update