LinuxCommandLibrary

cargo-run

Run the Rust project's main executable

TLDR

Run the default binary target

$ cargo [[r|run]]
copy

Run the specified binary
$ cargo [[r|run]] --bin [name]
copy

Run the specified example
$ cargo [[r|run]] --example [name]
copy

Activate a space or comma separated list of features
$ cargo [[r|run]] [[-F|--features]] "[feature1 feature2 ...]"
copy

Disable the default features
$ cargo [[r|run]] --no-default-features
copy

Activate all available features
$ cargo [[r|run]] --all-features
copy

Run with the given profile
$ cargo [[r|run]] --profile [name]
copy

SYNOPSIS

cargo run [OPTIONS] [--] [<ARGS>...]

PARAMETERS

--bin <NAME>
    Build and run the specified binary.

--example <NAME>
    Build and run the specified example.

--test <NAME>
    Build and run the specified integration test.

--bench <NAME>
    Build and run the specified benchmark.

-p SPEC, --package SPEC
    Package to build and run.

--release, -r
    Build in release (optimized) mode.

--target TRIPLE
    Target platform triple.

--manifest-path PATH
    Path to Cargo.toml.

--jobs N
    Number of parallel jobs.

-v, --verbose
    Verbose output.

-q, --quiet
    No output except errors.

--frozen
    No update to Cargo.lock.

--locked
    Use Cargo.lock as-is.

--offline
    Offline mode, no network.

-h, --help
    Print help.

--version, -V
    Print version.

DESCRIPTION

The cargo run command is a core subcommand of Cargo, Rust's build system and package manager. It automatically builds the current package in the current directory (or specified target) and then executes the resulting binary.

By default, it compiles and runs the binary in debug mode, which is suitable for development and testing. This command is especially useful during development as it saves the step of manually invoking cargo build followed by executing the binary.

It supports running specific binaries, examples, tests, or benches from the workspace. Arguments passed after -- are forwarded to the executed binary. Cargo tracks dependencies and rebuilds only what's necessary for efficiency.

Common use cases include quick iteration on command-line tools, web servers, or scripts. For production, pair it with --release for optimizations. It respects Cargo.toml configurations like [[bin]] sections.

CAVEATS

By default uses debug mode (slow); use --release for speed. Does not work with proc-macros or cdylib crates. Arguments after -- go to binary, not Cargo.

EXAMPLES

cargo run -- hello
cargo run --release -- --help
cargo run --example hello_utils

EXIT STATUS

0 on success; 101 if binary panics; inherits binary's exit code otherwise.

HISTORY

Introduced in Cargo 0.0.1 (2014) by Mozilla's Rust team. Evolved with Cargo's stabilization in Rust 1.0 (2015). Key enhancements in Cargo 1.0+ include workspace support and better incremental builds.

SEE ALSO

cargo build(1), cargo test(1), cargo check(1), rustc(1)

Copied to clipboard