Skip to content
Latchkey

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 --verbose

Common 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

FlagEffect
--bin <name>Run a named binary
--example <name>Run an example target
--releaseRun the optimized build
-- <args>Pass arguments to the program

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →