Problem with cargo fmt on solus linux

Hi, I've got a problem with using rustfmt:

When I do rustup component add rustfmt

I get info: component 'rustfmt' for target 'x86_64-unknown-linux-gnu' is up to date

And when I do cargo fmt

I get error: error: no such subcommand: fmt

Any idea?

1 Like

One guess would be that the cargo you’re using is not the one that rustup installed.

It should be, the only thing I did was to install rustup via my distribution's software center and then I let rustup do everything else.

cargo install fmt

I get the following error when I do cargo install fmt:

Updating index
error: specified package fmt v0.1.0 has no binaries

cargo install fmt
Updating index
Downloaded fmt v0.1.0
Downloaded 1 crate (927 B) in 17.42s

no problem ...!

try to reinstall rust

The fmt crate is unrelated to rustfmt, so cargo install fmt isn't what you're looking for.

It sounds like you've got a $PATH issue. Normally when cargo and rustc are installed with rustup they'll be placed in ~/.cargo/bin.

$ which cargo
$ which rustc

If you see something else there's a good chance you're using the cargo from your distro's package manager.

When you run cargo foo, cargo will look for a binary called cargo-foo on your $PATH and call it.

Also, when you add the rustfmt component it'll place rustfmt (the rust formatter) and cargo-fmt (a cargo subcommand wrapping rustfmt) in ~/.cargo/bin with cargo and rustc.

$ which cargo-fmt rustfmt

The easiest way to update your $PATH and make sure everything is configured is by sourcing the ~/.cargo/env file.

$ cat ~/.cargo/env
export PATH="$HOME/.cargo/bin:$PATH"
$ source ~/.cargo/env
$ echo $PATH | tr ':' '\n'                                                                                                           

Seems like I have path problems yes.

$ which cargo
$ which rustc

$ ls .cargo/

$ which cargo-fmt rustfmt
which: no cargo-fmt in (/sbin:/bin:/usr/sbin:/usr/bin:/snap/bin)
which: no rustfmt in (/sbin:/bin:/usr/sbin:/usr/bin:/snap/bin)

Looks like everything is in the wrong place... (for info, I use solus linux)
But basic commands like for example cargo new or cargo run are working fine.

I'd uninstall Rust via your distro's package manager and then install it using rustup (

Unless you're using a bleeding-edge distro like Arch linux, the version of Rust bundled with most package managers tends to be 6-18 months behind the times.

The first time I installed rust was via but I also had path problems (couldn't even do a cargo new).
The rustup is up to date in my package manager and it also downloaded the latest version of rust.

Seems like either way I'm going to have path problems :confused:

Looks like they are looking for a maintainer for these packages:

it is because you should restart you computer after installing rust, it may be the reason

It's strange because the rustup is up to date in the repositories: 1.21.1-10 (2019-12-21).

No, it didn't solve the problem.

which os you use ?

Solus linux.

is gcc already installed in your system
gcc --version
if not

  1. install gcc complier
  2. install rust (use official website)
  3. restart your system

Yes it is, otherwise I couldn't even compile. Cargo works with cargo new or cargo run, just not with manually installed commands like fmt.

Where did rustup put the cargo-fmt from rustup component add rustfmt? Because you're using the solus package I'm guessing it might be installed somewhere globally like /usr/local/bin/.

If you can figure out where rustup put cargo-fmt you'll be able to edit your ~/.bashrc to add that directory to your $PATH.

One way might be to remove the component then use strace to see which directories rustup is writing to (strace rustup component add rustfmt). I'm sure there's a way to ask rustup where it puts things, but don't know off the top of my head.

Also, do you run rustup as root? If so, rustfmt and cargo-fmt may have been placed in your root user's home directory (e.g. sudo ls /root/.cargo/bin/).

I don't have a /usr/local directory and it is not in /usr/bin where cargo, rustup, rustc... are.

Strace prints a LOT of things, I can't find anything in there.

No, not as root. It is not in the root directory.

I'll keep looking if I can find where rustup put cargo-fmt.