cargo run: Usage, Options & Common CI Errors
Compile and execute a binary in one step.
cargo run builds the current package, then runs its binary target. Everything after -- is forwarded to your program rather than to cargo.
What it does
Compiles (like cargo build) and immediately executes the resulting binary. If the package has more than one binary you must disambiguate with --bin.
Common usage
Terminal
cargo run # run the default binary
cargo run --release # run optimized binary
cargo run --bin server # pick a specific binary
cargo run --example demo # run an example
cargo run -- --port 8080 --verboseCommon CI error: multiple binaries
A workspace or multi-binary crate fails with "error: cargo run could not determine which binary to run. Use the --bin option to specify a binary." Fix: pass --bin <name>, or set default-run = "<name>" in the [package] section of Cargo.toml.
Options
| Flag | Effect |
|---|---|
| --bin <name> | Run a named binary |
| --example <name> | Run an example target |
| --release | Run the optimized build |
| -- <args> | Pass arguments to the program |
Related guides
Rust "cargo build failed" - Diagnose the Build Failure in CIFix a failing "cargo build" in CI -- a compile error, a missing native dependency, or a transient registry fe…
cargo build: Usage, Options & Common CI ErrorsWhat cargo build does, the flags you use most in CI (--release, --locked, --target), and how to fix the depen…
cargo install: Usage, Options & Common CI Errorscargo install builds and installs Rust binaries into ~/.cargo/bin. Learn --locked, --version, installing from…