error: toolchain 'stable-x86_64-apple-darwin' does not have the binary `rustfmt`
Asked Answered
S

3

31

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?

Squelch answered 22/12, 2017 at 17:11 Comment(1)
I think the first part of your question isn't relevant -- right now you're just having trouble with rustfmt from a clean rustup install. I am too..Rendering
N
25

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:

  1. Once you update Rustup to the latest version, you may receive the message 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.
  2. Run rustup update to let it fill in the deleted binaries with its own, managed rustfmt and cargo-fmt.
  3. Ensure that the toolchain that you wish to work with is installed (e.g. stable)
  4. Run the command above too ensure that the 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).

Numinous answered 22/12, 2017 at 17:33 Comment(1)
To add rustfmt-preview with that toolchain, you'll also need to install the toolchain: rustup install nightly-2017-12-20-x86_64-apple-darwinRendering
L
18

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 :)

Lascivious answered 15/5, 2018 at 13:59 Comment(1)
Thanks! This was what I needed for the "default" newbie install.Melba
S
1
$ rustup run stable rustfmt --version
error: `toolchain 'stable-x86_64-pc-windows-msvc' does not have th`e binary `rustfmt.exe`

$ rustup component remove rustfmt-preview --toolchain=stable-x86_64-pc-windows-msvc
info: removing component 'rustfmt-preview'
warning: during uninstall component rustfmt-preview-x86_64-pc-windows-msvc was not found

$ rustup component add rustfmt-preview --toolchain=stable-x86_64-pc-windows-msvc
info: downloading component 'rustfmt-preview'
info: installing component 'rustfmt-preview'

$ rustup run stable rustfmt --version
rustfmt 0.99.1-stable (da17b689 2018-08-04)

https://users.rust-lang.org/t/problem-with-rustfmt-on-stable/15165/7

Selaginella answered 29/10, 2018 at 3:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.