This error occurs because Rustup cannot find a default toolchain to use for your current project or environment. You can fix it by installing the stable toolchain and setting it as the default using the rustup default command.
If you have just installed Rustup or are on a fresh machine, the toolchain likely hasn't been initialized yet. Run the following command to install the latest stable version and set it as your default:
rustup install stable
rustup default stable
If you are working in a specific directory that requires a different version (e.g., an older Rust version for legacy code), you can override the default for that project only. Create a rust-toolchain.toml file in your project root with the desired version, or use the command line:
# Install a specific version (e.g., 1.70.0)
rustup install 1.70.0
# Set it as the default for the current directory only
rustup override set 1.70.0
If you are on a CI/CD pipeline or a container where Rustup is installed but the environment variables are missing, ensure the RUSTUP_HOME and CARGO_HOME paths are correctly set. Sometimes, simply sourcing the environment script resolves the issue:
source "$HOME/.cargo/env"
If you still see the error after running these commands, verify that your shell is actually loading the .cargo/bin directory in your PATH. You can check this by running which rustc or rustc --version. If rustc is not found, your shell configuration (like .bashrc, .zshrc, or .profile) is likely missing the line that sources the Cargo environment. Add source "$HOME/.cargo/env" to your shell config file and reload it with source ~/.bashrc (or the equivalent for your shell).
In rare cases where you have multiple Rust installations (e.g., one from a package manager like apt or brew and one from rustup), the system might be picking up the wrong binary. Ensure rustup is the one being called by checking which rustup and removing conflicting package-manager installations if necessary. Once the correct toolchain is installed and the environment is sourced, the "no default toolchain configured" error will disappear.