Rust book: create, build, and run a project with Cargo
Answer: Cargo is Rust's build system and package manager. This chapter shows how to create, build, run, and check a small project with it.
Creating a project
Cargo is Rust's build system and package manager. Most Rustaceans use this tool. Because the vast majority of Rust projects use Cargo, the rest of this book assumes it. If you see a version number, you have it.
cargo new hello_cargo creates a directory and project with that name, plus a Git repository and a .gitignore file, unless you already are inside a Git repository.
Cargo.toml is in TOML format, Cargo's configuration format. The [package] section holds the name, version, and edition Cargo needs to compile the package. [dependencies] is where you list any of your project's dependencies.
Cargo places source files in the src directory. src/main.rs is a generated Hello, world! program, like the one written earlier in the chapter without Cargo.
Build, run, check, and release
This command creates an executable file in target/debug/hello_cargo, or the Windows equivalent, rather than next to the source. cargo run builds and runs a project in one step.
cargo check looks for errors without producing a binary, which is often much faster than cargo build.
Cargo new starts a project. Cargo build compiles it. Cargo run compiles and then starts the program. Cargo check quickly checks your code without producing an executable.
When the project is ready for release, cargo build --release produces an optimized build.
See also
Claims
- id: C1 claim: Cargo is Rust's build system and package manager. source: S1 evidence: "Cargo is Rust's build system and package manager"
- id: C2 claim: cargo new creates a project; cargo build builds it; cargo run builds and runs it. source: S2 evidence: "We can create a project using
cargo new"
- id: C3 claim: cargo build writes an executable under target/debug, not beside the source. source: S2 evidence: "This command creates an executable file in _target/debug/hello_cargo_"
Sources
- [S1] Hello, Cargo!. The Rust Project Developers. https://doc.rust-lang.org/book/ch01-03-hello-cargo.html . License: MIT OR Apache-2.0. Accessed 2026-11-27.
- [S2] Hello, Cargo! (source). The Rust Project Developers. https://raw.githubusercontent.com/rust-lang/book/main/src/ch01-03-hello-cargo.md . License: MIT OR Apache-2.0. Accessed 2026-11-27.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Project Developers, Hello, Cargo!; The Rust Project Developers, Hello, Cargo! (source). MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Rust Project Developers, Hello, Cargo!; The Rust Project Developers, Hello, Cargo! (source). MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers.
Cite this
iinventedlight. 2026. "Rust book: create, build, and run a project with Cargo." iinventedlight Library, iil:note:9fy3pxwn, version of 2026-11-27. https://iinventedlight.com/library/notes/rust-hello-cargo/. License: CC-BY-4.0.
@misc{iil_note_9fy3pxwn,
author = {{iinventedlight}},
title = {{Rust book: create, build, and run a project with Cargo}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-27},
url = {https://iinventedlight.com/library/notes/rust-hello-cargo/},
note = {Permanent ID iil:note:9fy3pxwn. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- rust-hello-cargo.schema.json (schema; CC-BY-4.0)
- rust-hello-cargo.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-hello-cargo.md.