Skip to content

Commit cb1ec60

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

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

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

Lines changed: 54 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,57 @@ 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 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

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ 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
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`.
7273
Now you should be able to run `rustup`, `rustc`, `cargo`, etc. normally.
7374

75+
[correctly exposed]: ./already-installed-rust.html#ensure-the-correct-path-configuration
76+
7477
### APT
7578

7679
Starting from Debian 13 (trixie) and Ubuntu 24.04 (noble),

0 commit comments

Comments
 (0)