I've run rustup update
to update my toolchain and saw two warnings:
warning: tool `rustfmt` is already installed, remove it from `/Users/<username>/.cargo/bin`, then run `rustup update` to have rustup manage this tool. warning: tool `cargo-fmt` is already installed, remove it from `/Users/<username>/.cargo/bin`, then run `rustup update` to have rustup manage this tool.
I followed the instructions in the warning messages, then tried to run rustfmt
again. I got the error
error: toolchain 'stable-x86_64-apple-darwin' does not have the binary rustfmt`
What went wrong and how can I fix it?
The most standard and reliable way to have rustfmt
in your system is to ensure that the rustfmt
component is installed in your Rustup toolchain.
rustup component add rustfmt
Or for a specific toolchain:
rustup component add rustfmt --toolchain nightly-2020-06-09
There is a possibility that the tests and builds in nightly toolchains fail, which means that those are not as likely to always have this component. The latest stable
and beta
toolchains will usually have it in accordance to the No Tool Breakage Week policy.
In order to let Rustup manage rustfmt
, see the following steps:
warning: tool rustfmt is already installed
. Remove the binaries from Cargo's binary folder, as suggested. cargo uninstall rustfmt
(or rustfmt-nightly
if you installed that) works well.rustup update
to let it fill in the deleted binaries with its own, managed rustfmt
and cargo-fmt
.stable
)rustfmt
component is installed for that toolchain.With that done, calling rustfmt
will work as intended:
$ rustup run stable rustfmt --version rustfmt 1.4.12-stable (a828ffea 2020-03-11)
Or via the Cargo subcommand:
$ cargo fmt --version rustfmt 1.4.12-stable (a828ffea 2020-03-11)
In the early days, rustfmt
managed by Rustup could have been a bit confusing, because Rustup did not always have rustfmt
, and would still too often emerge as a preview component which had to be installed under the name rustfmt-preview
. There are a few relevant issues and PRs on the subject (#1305 and #1310).
The Error tells you that you don't have the rustfmt-preview
is not installed on the actual *-apple-darwin
.
what you need to do is:
rustup component add rustfmt-preview --toolchain stable-x86_64-apple-darwin
after you'll be good to go :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With