← All notes

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

Sources

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

Permanent ID: iil:note:9fy3pxwn

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.},
}

Markdown

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.

All artifact files (JSON index)

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.