I tried installing rustfmt, but the installation instructions in the README.md seem outdated and I couldn't figure out how to install rustfmt correctly.
I tried:
$ cargo install rustfmt
error: binary `cargo-fmt` already exists in destination
binary `rustfmt` already exists in destination
Add --force to overwrite
This is the first time I tried using rustfmt. Is is normally preinstalled?
(I also tried installing with --force)
$ cargo fmt
error: 'cargo-fmt' is not installed for the toolchain 'stable-x86_64-unknown-linux-gnu'
To install, run `rustup component add rustfmt`
$ rustup component add rustfmt
error: toolchain 'stable-x86_64-unknown-linux-gnu' does not contain component 'rustfmt' for target 'x86_64-unknown-linux-gnu'
At least the error message tried ^^
$ rustup install nightly
$ cargo +nightly install --force rustfmt
$ cargo +nightly fmt
This version of rustfmt is deprecated. Use rustfmt-nightly. Use --force to run deprecated rustfmt.
Aparrently, I installed the wrong version. But:
$ rustup component add rustfmt --toolchain nightly
info: component 'rustfmt' for target 'x86_64-unknown-linux-gnu' is up to date
My setup:
Linux (Ubuntu 18.04)
rustup 1.16.0 (beab5ac2b 2018-12-06)
rustc 1.31.1 (b6c32da9b 2018-12-18)
cargo 1.31.0 (339d9f9c8 2018-11-16)
Can someone correct the installation instructions in the README.md? Thank you ^^
I was able to figure it out myself :)
Aparrently the right command was
cargo +nightly install --force rustfmt-nightly
And it can be used with cargo fmt, the +nightly isn't necessary.
You should use rustup component add rustfmt which is what is in the README. I think you might be looking at an old version of the readme.
Sorry to reopen but I've run into this as well, rustup component add rustfmt doesn't appear to work for me:
$ rustup --version
rustup 1.16.0 (beab5ac2b 2018-12-06)
$ rustc --version
rustc 1.31.1 (b6c32da9b 2018-12-18)
$ rustup component add rustfmt
error: toolchain 'stable-x86_64-unknown-linux-gnu' does not contain component 'rustfmt' for target 'x86_64-unknown-linux-gnu'
I had done a rustup update earlier today to get to 1.31 and didn't have rustfmt installed previously.
You might need to do rustup self update, its also possibly a bug in Rustup
Thank you, it does appear to be a bug in Rustup, the solution at https://github.com/rust-lang/rustup.rs/issues/1558#issuecomment-452110409 solved the problem for me:
rustup toolchain remove stable && rustup toolchain install stable
Most helpful comment
Thank you, it does appear to be a bug in Rustup, the solution at https://github.com/rust-lang/rustup.rs/issues/1558#issuecomment-452110409 solved the problem for me: