@@ -7,6 +7,8 @@ will complain that you already have Rust installed in `/usr` and refuse to
77install. However, you can install Rust via ` rustup ` and have it coexist with
88your packaged Rust toolchain.
99
10+ ## Set up rustup with an existing Rust toolchain
11+
1012When you initially install Rust with ` rustup ` , pass the ` -y ` option to make it
1113ignore the packaged Rust toolchain and install a ` rustup ` -managed toolchain
1214into ` ~/.cargo/bin ` . Add that directory to your ` $PATH ` (or let ` rustup ` do it
@@ -28,5 +30,57 @@ you may want to make it your [default toolchain]:
2830rustup default system
2931```
3032
33+ ## Ensure the correct ` $PATH ` configuration
34+
35+ There are times when the above steps don't work, and you may see strange error
36+ messages when running commands that should have been proxied by rustup.
37+ For example, when running ` cargo +stable --version ` , you may encounter the
38+ following error:
39+
40+ ``` text
41+ error: no such command: `+stable`
42+
43+ Cargo does not handle `+toolchain` directives.
44+ Did you mean to invoke `cargo` through `rustup` instead?
45+ ```
46+
47+ This means ` cargo ` is currently not a ` rustup ` proxy, and your ` $PATH ` needs
48+ to be fixed.
49+
50+ In fact, on any machine with rustup installed, you would expect ** rustup
51+ proxies to come first in ` $PATH ` ** , shadowing any other Rust installations.
52+ Don't worry: these shadowed installations can then be adopted by rustup with the
53+ ` rustup toolchain link ` command as mentioned above.
54+
55+ The exact steps to be taken to address the ` $PATH ` issue may vary according to your
56+ system environment, but usually it is about changing the evaluation order of certain
57+ lines in your shell configuration file(s).
58+
59+ To make it clearer, let's look at the example of a common conflict between the
60+ regular rustup downloaded from [ rustup.rs] and homebrew-installed ` rust ` on macOS.
61+ In your ` .profile ` , you can probably find these two lines in this order:
62+
63+ ``` bash
64+ . $HOME /.cargo/env
65+ eval $( /opt/homebrew/bin/brew shellenv)
66+ ```
67+
68+ In this example, both of these lines all _ prepend_ to ` $PATH ` , so the last one
69+ takes over, letting the homebrew-installed ` rust ` shadow the rustup proxies,
70+ causing the error. At this point, it should be clear that exchanging these two
71+ lines will fix the issue.
72+
73+ After the fix, the output of ` cargo +stable --version ` should be similar to one
74+ of the following, depending on whether you have had the ` stable ` toolchain installed:
75+
76+ - ``` text
77+ cargo 1.85.1 (d73d2caf9 2024-12-31)
78+ ```
79+
80+ - ``` text
81+ error: toolchain 'stable' is not installed
82+ ```
83+
84+ [ rustup.rs ] : https://rustup.rs
3185[ toolchain override shorthand ] : ../overrides.md#toolchain-override-shorthand
3286[ default toolchain ] : ../overrides.md#default-toolchain
0 commit comments