rustc: command not found
The “rustc: command not found” error means the Rust compiler is not installed or not accessible from your shell. Rust code cannot be compiled without rustc, and you need it to run any Rust program directly from the command line.
What It Means
rustc is the Rust compiler binary. When you type rustc main.rs, your operating system searches the PATH for this executable. If it is not found — either because Rust is not installed or the binary directory is not in PATH — the shell returns “rustc: command not found”.
Why It Happens
- Rust is not installed on your system.
- Rust was installed via rustup but the toolchain is not active.
- The
~/.cargo/bindirectory is not in yourPATH. - You installed only Cargo via a package manager without
rustc. - The shell configuration file does not source the Cargo environment.
- The rustup installation script was not run to completion.
How to Fix It
1. Install Rust using rustup
The standard method installs both rustc and cargo:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shSelect option 1 (default) to proceed with the installation.
2. Add Cargo’s bin directory to PATH
After installation, ensure ~/.cargo/bin is in your PATH:
export PATH="$HOME/.cargo/bin:$PATH"
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc3. Verify the compiler is installed
Run the version check to confirm:
rustc --version
rustc 1.77.0 (aabcdef01 2024-03-06)4. Check the active toolchain
If rustc is still not found, verify your rustup configuration:
rustup show
# Lists active toolchain and installed targets
rustup default stable5. Install a specific toolchain if needed
You can install and switch between multiple Rust versions:
rustup toolchain install nightly
rustup default nightly
rustc --versionFAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro