← 返回命令列表

Linux command

cargo 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Build

cargo build

Run

cargo run

Test

cargo test

Create

cargo new [project-name]

Add

cargo add [dependency]

Update

cargo update

说明

cargo is the Rust package manager and build system. It handles dependency management, compiling packages, running tests, generating documentation, and publishing crates to crates.io. The tool is essential for Rust development and comes bundled with Rust.

参数

new _name_
Create new project
build --release
Compile project
run
Build and run
test
Run tests
check
Check compilation without building
add _crate_
Add dependency
install _crate_
Install binary crate
publish
Publish to crates.io
doc --open
Build documentation
clean
Remove build artifacts
update
Update dependencies
bench
Run benchmarks (nightly or harness-provided).
fmt
Format code via `rustfmt` (component).
clippy
Run the Clippy linter (component).

FAQ

What is the cargo command used for?

cargo is the Rust package manager and build system. It handles dependency management, compiling packages, running tests, generating documentation, and publishing crates to crates.io. The tool is essential for Rust development and comes bundled with Rust.

How do I run a basic cargo example?

Run `cargo build` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does new _name_ do in cargo?

Create new project