rustup-which
Find the installed rustc executable
TLDR
Display the path to the binary in the default toolchain
Display the path to the binary in the specified toolchain (see rustup help toolchain for more information)
SYNOPSIS
rustup [--toolchain TOOLCHAIN] which COMMAND
PARAMETERS
COMMAND
The name of the Rust executable to locate (e.g., rustc, cargo, rustdoc). The command must be part of a Rust toolchain managed by rustup.
--toolchain TOOLCHAIN
(Optional, global rustup option) Specifies the Rust toolchain to search within, overriding the currently active or default toolchain. Examples include stable, beta, nightly, or specific version strings like 1.70.0.
DESCRIPTION
rustup-which is a subcommand of the rustup toolchain manager. It serves to identify the exact absolute path to a Rust-related executable (such as rustc, cargo, rustdoc, etc.) that rustup would execute based on the currently active or specified toolchain.
This command is invaluable for debugging environment PATH issues, verifying which version of a Rust command is being used, or scripting operations that require direct access to toolchain binaries.
When invoked, rustup-which searches within the directories managed by rustup for the specified command. If found, it prints the absolute path to standard output. It is particularly useful in environments where multiple Rust toolchains (e.g., stable, beta, nightly, or specific versions) are installed, helping users understand which specific binary will be invoked by rustup's shim system. It ensures that the correct toolchain binary is identified, especially when dealing with projects that require a specific Rust version or when trying to isolate issues related to toolchain discrepancies.
CAVEATS
The command only finds executables managed by the rustup toolchain system. It will not locate Rust binaries installed manually or through other package managers if they are not integrated with rustup.
The path returned by rustup-which typically points to a rustup 'shim' executable, which then redirects to the actual binary within the toolchain directory. For most purposes, this shim path is the correct and intended execution path.
EXIT STATUS
rustup-which exits with status 0 if the specified command is found and its path is successfully printed. It exits with a non-zero status (typically 1) if the command is not found within the active or specified toolchain, or if an error occurs.
OUTPUT
The command prints the absolute path of the located executable to standard output (stdout), followed by a newline character. No output is produced on stdout if the command is not found, although an error message might be printed to standard error (stderr).
HISTORY
rustup-which is an integral part of the rustup toolchain installer, which was initially released in 2016 to standardize the management of Rust versions and targets. It has been a stable and fundamental utility within the rustup ecosystem since its early development, providing a consistent way to query the location of Rust toolchain components.