Skip to content
cargo: command not found

cargo: command not found

DodaTech 2 min read

The “cargo: command not found” error means your shell cannot locate the Cargo build tool. Cargo is Rust’s package manager and build system, and it is installed as part of the Rust toolchain through rustup or alternative installation methods.

What It Means

When you type cargo build or any cargo command, your operating system searches through the directories in the PATH environment variable. If the Cargo binary is not found in any of those directories, the shell returns “cargo: command not found”.

Why It Happens

  • Rust and Cargo are not installed on your system.
  • Rust was installed but the Cargo binary directory is not in your PATH.
  • You installed Rust via a package manager that placed binaries in a non-standard location.
  • Your shell configuration does not source the Cargo environment.
  • The rustup installation was interrupted or incomplete.

How to Fix It

1. Install Rust via rustup (recommended)

The official way to install Rust and Cargo is through rustup:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Follow the on-screen prompts. Choose the default installation option unless you need a custom setup.

2. Source the Cargo environment

After installation, rustup prompts you to add Cargo to your PATH. If you missed that step:

# Add to ~/.bashrc or ~/.zshrc
source "$HOME/.cargo/env"

Or add the path manually:

export PATH="$HOME/.cargo/bin:$PATH"

Apply the changes:

source ~/.bashrc
cargo --version

3. Verify the installation

Confirm that Cargo is installed correctly:

cargo --version
cargo 1.77.0 (e1234c567 2024-03-06)

rustc --version
rustc 1.77.0 (aabcdef01 2024-03-06)

4. Restart your terminal session

If Cargo still is not found, restart your terminal or run:

exec $SHELL

Then test again:

cargo init hello_cargo
cd hello_cargo
cargo build

5. Check for multiple Rust installations

If you previously installed Rust through a package manager, it may conflict with rustup:

which cargo
# If it points to /usr/bin/cargo, you may have a system package installation

Use rustup to manage multiple toolchains and avoid conflicts.

FAQ

Do I need to install Rust separately if I install Cargo?
Cargo is bundled with the Rust toolchain. Installing via rustup gives you both rustc (the compiler) and cargo (the build tool) in one step. There is no separate Cargo-only installer.
What is the difference between rustup, rustc, and cargo?
rustup is the toolchain manager for installing and switching Rust versions. rustc is the Rust compiler. cargo is the build system and package manager. Install via rustup, and you get all three.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro