Skip to content
rustc: command not found

rustc: command not found

DodaTech 2 min read

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/bin directory is not in your PATH.
  • 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 | sh

Select 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 ~/.bashrc

3. 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 stable

5. Install a specific toolchain if needed

You can install and switch between multiple Rust versions:

rustup toolchain install nightly
rustup default nightly
rustc --version

FAQ

Can I use Rust without rustc?
No. rustc is the Rust compiler. Every Rust program must be compiled, either directly with rustc or indirectly through cargo build, which calls rustc internally. You cannot run .rs files without compiling them first.
What is the difference between rustc and cargo?
rustc is the compiler that translates Rust source code into machine code. cargo is the build system that manages dependencies, calls rustc with the correct flags, and handles project structure. Most developers use cargo instead of calling rustc directly.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro