Sub topic 3
Checking that the install worked
This chapter assumes you have run the rustup installer from the previous chapter and can use a terminal. You should know what a PATH environment variable is, at least roughly. By the end, you will be able to confirm that each part of the toolchain is installed and reachable. You will also be able to read the output, and tell which failures mean the install is broken and which mean the shell is stale.
Why verification is a separate step
The installer can finish without error and still leave you with a terminal that cannot find cargo. The installer copies binaries into a directory, then edits shell startup files so that directory appears on your PATH. Your running shell read its startup files before the installer changed them. So it does not know about the change yet.
Verification answers three questions:
- Are the binaries present?
- Can the shell find them (are they on
PATH)? - Are they the versions you expect (channel and release)?
The three version commands
Run these in a terminal:
rustc --version
cargo --version
rustup --versionEach command prints one line. On a stable install it looks like this, though the numbers will differ for you:
rustc 1.83.0 (90b35a623 2024-11-26)
cargo 1.83.0 (5ffbef321 2024-10-29)
rustup 1.27.1 (54dd3d00f 2024-04-24)The three tools answer different questions, so the output of each tells you something different.
| Command | Tool | What the output tells you |
|---|---|---|
| `rustc --version` | The compiler | The release number, a short commit hash, and the commit date of the compiler that will run |
| `cargo --version` | The build tool and package manager | The Cargo release that ships with that toolchain |
| `rustup --version` | The toolchain manager | The version of rustup itself, which updates separately from the compiler |
Two details are worth knowing.
rustcandcargocome from the same toolchain, so their release numbers match. The Cargo commit hash and date differ from the compiler's because Cargo is a separate codebase. The release number (such as 1.83.0) is what matters.rustuphas its own version line. It is not tied to the Rust release number.
If you installed a nightly or beta toolchain, the output carries a suffix such as -nightly or -beta.1. That suffix is how you recognize a non-stable channel.
Why `rustc` and `cargo` are not real binaries
The files in ~/.cargo/bin (or %USERPROFILE%\.cargo\bin on Windows) for rustc and cargo are small proxies. They are links to rustup. When you run cargo, rustup decides which installed toolchain applies, then runs that toolchain's real cargo.
This is why verification also tells you something about toolchain selection. The proxy resolves the toolchain in this order:
- An override on the command line, such as
cargo +nightly build. - The
RUSTUP_TOOLCHAINenvironment variable. - A directory override set with
rustup override. - A
rust-toolchain.tomlfile in the current directory or a parent. - The default toolchain.
For a fresh install, only the default toolchain exists, so this is simple. It matters later when a project pins a different version.
Asking rustup what it installed
The version lines show what runs. rustup can also report what is installed and which toolchain is active:
rustup showThe output lists the host platform, the install directory, installed toolchains, and the active toolchain with its compiler version. A typical result on Linux:
Default host: x86_64-unknown-linux-gnu
rustup home: /home/you/.rustup
stable-x86_64-unknown-linux-gnu (default)
rustc 1.83.0 (90b35a623 2024-11-26)Two fields are useful for troubleshooting:
- The host triple (
x86_64-unknown-linux-gnuabove) describes your platform and ABI. On Windows it ends in-msvcor-gnu. This tells you which linker the toolchain expects. rustup homeshows where toolchains are stored. The format ofrustup showvaries a little between rustup releases, so look for these fields rather than matching exact lines.
Finding which binary is running
If a version command works but prints something unexpected, check which file the shell is running. This catches a second Rust installation, for example one from a system package manager that sits earlier on PATH.
which rustc
which cargoOn Windows PowerShell, use Get-Command rustc instead.
The expected result is a path inside the Cargo bin directory:
/home/you/.cargo/bin/rustc
/home/you/.cargo/bin/cargoIf the path points somewhere else, such as /usr/bin/rustc, you are running a distribution-packaged compiler. It is not managed by rustup, so rustup update will not change it. Either remove the packaged version or put ~/.cargo/bin earlier on PATH.
Reading failures
Most verification failures fall into a small number of patterns.
| Symptom | Likely cause | First thing to try |
|---|---|---|
| `command not found: rustc` (or `cargo`) on Linux or macOS | The shell has not loaded the updated `PATH` | Open a new terminal, or run `. "$HOME/.cargo/env"` |
| `'rustc' is not recognized as an internal or external command` on Windows | The terminal was opened before the install | Close it and open a new one |
| `rustc` works, but `which rustc` shows a path outside `~/.cargo/bin` | Another Rust install shadows rustup's | Reorder `PATH` or remove the other install |
| `rustup: command not found` but you ran the installer | The installer failed partway, or it edited a different shell's startup file | Re-run the installer and read its final messages |
| Version commands work, but builds later fail with a linker error | A C linker is missing | See the troubleshooting chapter |
Note the last row. The version commands never invoke a linker. They can all succeed on a machine that still cannot build a program. This means a clean version check proves the tools are installed and reachable, not that compilation works end to end.
The stale shell fix
For the most common failure, you can load the new PATH without opening a terminal. On Linux and macOS the installer writes an environment script at ~/.cargo/env. Source it:
. "$HOME/.cargo/env"Then repeat the version commands. This fixes only the current terminal session. New terminals should work without it, because the installer also edited your shell profile. If new terminals still fail, the installer may have edited a profile your shell does not read. For example, it may have changed ~/.profile while your shell reads ~/.zshrc. Add the line above to the file your shell reads.
An end-to-end smoke test
To go beyond the version lines and confirm the compiler can produce a working program, compile a one-file program directly with rustc. Create a file named check.rs:
fn main() {
println!("Rust is working");
}Compile and run it:
rustc check.rs
./checkOn Windows, run check.exe instead of ./check. The program should print Rust is working.
This test exercises the compiler and the linker. If it fails with a message about cc or link.exe, your toolchain is installed but your system lacks the linker it needs. That is a different problem from a missing PATH entry, and the troubleshooting chapter covers it.
You can delete check.rs and the generated check binary afterwards. The next chapter uses Cargo to create projects, so you will not need the bare rustc workflow again for ordinary work.
Checking for updates without changing anything
rustup check reports whether newer releases exist for your installed toolchains. It does not install anything:
rustup checkSample output:
stable-x86_64-unknown-linux-gnu - Up to date : 1.83.0 (90b35a623 2024-11-26)
rustup - Up to date : 1.27.1Use this when you want to know whether a version problem comes from being out of date. Actually updating is covered in a later chapter.
A short verification checklist
- Open a new terminal so that it reads the updated profile.
- Run
rustc --version,cargo --version, andrustup --version. All three should print a line. - Run
which rustcand confirm the path is inside the Cargo bin directory. - Run
rustup showand confirm the active toolchain is the one you intended. - Compile and run
check.rsto confirm the linker works.
If all five steps pass, the toolchain is ready for the next chapter, where you create a project with cargo new.
Exercise
You run cargo --version right after installing and get "command not found". Running ls ~/.cargo/bin shows cargo, rustc, and rustup are all present. What is the most likely cause, and what are two ways to fix it without reinstalling?
Show answer
The binaries exist, but the current shell's PATH does not include ~/.cargo/bin, because the shell started before the installer edited the profile. Fix it by opening a new terminal, or by running . "$HOME/.cargo/env" in the current one. If new terminals also fail, add that line to the startup file your shell actually reads.
Exercise
rustc --version and cargo --version both succeed, yet cargo build later fails with an error that the linker cc was not found. Why did the version checks not catch this, and which quick test would have?
Show answer
The version commands only run the proxies and print a string, and neither invokes a linker. Compiling and running a small program with rustc check.rs would have caught it, because producing an executable requires the linker.
Exercise
rustc --version prints a version, but which rustc shows /usr/bin/rustc. Why is this a problem, and how do you fix it?
Show answer
The compiler comes from a system package rather than rustup, so rustup commands such as rustup update and rustup default do not control it. Fix it by removing the packaged compiler, or by placing ~/.cargo/bin before /usr/bin on PATH so that the rustup proxy is found first.