Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

rust

rustup

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?

like image 539
dvnguyen Avatar asked Dec 22 '17 17:12

dvnguyen


2 Answers

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

like image 137
E_net4 stands with Ukraine Avatar answered Sep 21 '22 04:09

E_net4 stands with Ukraine


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

like image 35
cooljl86 Avatar answered Sep 19 '22 04:09

cooljl86