Install Rust and use Cargo
Install Rust and use Cargo
A local Rust project needs the Rust toolchain: rustc compiles source, Cargo manages projects and dependencies, and rustup manages installed toolchains. Follow the official installation instructions for your operating system. An editor can help, but it does not replace the compiler.
Check rustc --version and cargo --version. Create a project with cargo new school, enter its directory and replace src/main.rs with the program below. Run cargo run. For a standalone file, rustc --edition=2024 main.rs builds it; run ./main on macOS/Linux or .\main.exe on Windows.
What you’ll learn
- Create and run a Cargo console project.
- Identify whether a failure concerns tooling, source or launching.
Install Rust and use Cargo in action
Install rustup tooling
Cargo first checks and builds the project, then launches the executable.
Install rustup toolingBuild src/main.rs
Its build messages are separate from the program output shown here.
Build src/main.rsRun the executable
Cargo.toml describes the package and its edition; Cargo.lock records resolved dependency versions.
Run the executable
Work through the Rust program
Save the complete source as main.rs in the Rust environment. No standard input is needed.
Rust 2024 · complete program
fn main() { println!("Rust setup ready"); }Expected output
Rust setup readyFollow the execution
Cargo first checks and builds the project, then launches the executable. Its build messages are separate from the program output shown here. Cargo.toml describes the package and its edition; Cargo.lock records resolved dependency versions.
Try the complete program in the Rust compiler. For tests, Cargo commands and local files, use the specified local environment.
Try a small variation
Your task: What should you investigate if cargo is not found?
Rust 2024 · complete program
fn main() { println!("Rust setup ready"); }Worked answer
Check installation and the shell path. Editing the greeting cannot make an unavailable tool appear; reopen the shell if the installer changed its environment.
Mistakes and limits to recognize
Examples use Rust 2024 edition and the standard library unless a section explicitly says otherwise. A dependency download needs network access. Toolchain versions change, so follow the linked installation guide rather than assuming a version number is permanently current.
Check your understanding
Take the idea into your next program
Check installation and the shell path. Editing the greeting cannot make an unavailable tool appear; reopen the shell if the installer changed its environment. Examples use Rust 2024 edition and the standard library unless a section explicitly says otherwise.
Further reading: the official Rust Book on install rust and use cargo.
Reaching the recap and completing the quizzes are separate milestones.