Skip to content

Commit a9f9cdb

Browse files
committed
docs(user-guide): cover correct $PATH configuration for proxies
1 parent b553aaf commit a9f9cdb

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

doc/user-guide/src/installation/already-installed-rust.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ will complain that you already have Rust installed in `/usr` and refuse to
77
install. However, you can install Rust via `rustup` and have it coexist with
88
your packaged Rust toolchain.
99

10+
## Set up rustup with an existing Rust toolchain
11+
1012
When you initially install Rust with `rustup`, pass the `-y` option to make it
1113
ignore the packaged Rust toolchain and install a `rustup`-managed toolchain
1214
into `~/.cargo/bin`. Add that directory to your `$PATH` (or let `rustup` do it
@@ -28,5 +30,63 @@ you may want to make it your [default toolchain]:
2830
rustup 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 like to have **rustup
51+
proxies showing up 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 make rustup proxies come first may vary according
56+
to your system environment, but usually it is about changing the evaluation
57+
order of certain lines in your shell configuration file(s).
58+
59+
To make it clearer, let's look at the example of a Mac with both regular rustup
60+
fetched from [rustup.rs] and homebrew-installed `rust`.
61+
The **right way** to configure `.profile` in this environment would be:
62+
63+
```bash
64+
eval $(/opt/homebrew/bin/brew shellenv)
65+
. $HOME/.cargo/env
66+
```
67+
68+
In this example, both of these lines all _prepend_ to `$PATH`, so the last one
69+
takes over, letting the rustup proxies shadow the homebrew-installed `rust`.
70+
On the other hand, putting these lines the other way around will cause the
71+
aforementioned error.
72+
73+
When in doubt, you can always debug your shell configuration by printing the
74+
status of your current `$PATH` with `echo $PATH | xargs -n1` and paying
75+
attention to the order of `$CARGO_HOME/bin` (which defaults to
76+
`$HOME/.cargo/bin`) compared to your package manager's `bin` directory.
77+
78+
After the fix, the output of `cargo +stable --version` should be similar to one
79+
of the following, depending on whether you have had the `stable` toolchain
80+
installed:
81+
82+
- ```text
83+
cargo 1.85.1 (d73d2caf9 2024-12-31)
84+
```
85+
86+
- ```text
87+
error: toolchain 'stable' is not installed
88+
```
89+
90+
[rustup.rs]: https://rustup.rs
3191
[toolchain override shorthand]: ../overrides.md#toolchain-override-shorthand
3292
[default toolchain]: ../overrides.md#default-toolchain

doc/user-guide/src/installation/other.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ After installing rustup with your favorite package manager, there are usually tw
6363
```
6464

6565
This will allow you to perform the initial setup of `rustup`, populate all the proxies
66-
managed by rustup, and install a default toolchain. When the installation is completed,
67-
please make sure that these proxies (usually under `$HOME/.cargo/bin`) are exposed via your `$PATH`.
66+
managed by rustup, and install a default toolchain.
6867

6968
> As of 2024/12/23, this is the case for
7069
> [DNF](https://developer.fedoraproject.org/tech/languages/rust/further-reading.html).
7170
72-
Now you should be able to run `rustup`, `rustc`, `cargo`, etc. normally.
71+
When the installation is completed, please make sure that the rustup proxies
72+
(usually under `$HOME/.cargo/bin`) are [correctly exposed] via your `$PATH`,
73+
and you should be able to run `rustup`, `rustc`, `cargo`, etc. normally.
74+
75+
[correctly exposed]: ./already-installed-rust.html#ensure-the-correct-path-configuration
7376

7477
### APT
7578

0 commit comments

Comments
 (0)