Sub topic 1
What rustup, rustc, and Cargo each do
Prerequisites
Assume you can use a terminal and understand that a compiler turns source code into a runnable program. You also need Linux, macOS, or Windows with internet access.
What rustup, rustc, and Cargo each do
Rust development uses three main tools:
| Tool | Purpose |
|---|---|
| `rustup` | Installs and selects Rust toolchains |
| `rustc` | Compiles Rust source code |
| Cargo | Creates projects, manages dependencies, and runs builds and tests |
A toolchain is a collection of compatible development tools. rustup installs a toolchain and can switch between release channels such as stable, beta, and nightly. rustc is the compiler inside that toolchain. Cargo is Rust's build system and package manager. It normally calls rustc for you.
Installing Rust with rustup
On Linux and macOS, install the stable toolchain with the official installer:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shOn Windows, download and run rustup-init.exe from the official Rust website. Follow the installer's default choices unless your system requires a custom setup. Restart your terminal after installation if it does not find the new commands.
Checking that the install worked
Run these commands:
rustc --version
cargo --version
rustup --versionEach command should print a version. If rustc and Cargo work, rustup has installed and selected a usable toolchain.
Fixing a missing linker or PATH problem
A linker combines compiled pieces into an executable. Rust may report a missing linker when your operating system lacks its C build tools.
- On Debian or Ubuntu, install
build-essential. - On Fedora, install the development tools group.
- On macOS, install Xcode Command Line Tools with
xcode-select --install. - On Windows, install the required Visual Studio C++ build tools.
If the shell reports command not found: cargo, inspect your PATH. Open a new terminal first. If the problem remains, add Cargo's bin directory to your shell configuration, then restart the shell.
Exercise
Which tool should you use to select a Rust release channel, and which tool compiles Rust code?
Show answer
Use rustup to select the channel. rustc compiles Rust code.