Rust 内置了一个包管理器 cargo。它会随着 Rust 的安装而安装。
cargo 类似于 Python 中的 pip 或 Ruby 中的 RubyGems 或 Node.js 中的 NPM。
当然了,cargo 不仅仅是一个包管理器,它还是 Rust 的项目管理利器。
检查 cargo 是否安装和安装的版本
打开终端或命令行提示符或 Shell,输入下面的命令然后回车
cargo --version
如果已经安装,则输出结果类似于
cargo 1.35.0
cargo 包管理器的版本和 Rust 语言是同步的。
cargo 的帮助信息
如果想要查看 cargo 的帮助信息或查看 cargo 提供了哪些命令和功能,可以在 终端 中输入 cargo 或 cargo -h 然后回车
输出结果类似于
Rust's package manager
USAGE:
cargo [OPTIONS] [SUBCOMMAND]
OPTIONS:
-V, --version Print version info and exit
--list List installed commands
--explain Run `rustc --explain CODE`
-v, --verbose Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z ... Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
-h, --help Prints help information
Some common cargo commands are (see all commands with --list):
build Compile the current package
check Analyze the current package and report errors, but don't build object files
clean Remove the target directory
doc Build this package's and its dependencies' documentation
new Create a new cargo package
init Create a new cargo package in an existing directory
run Run a binary or example of the local package
test Run the tests
bench Run the benchmarks
update Update dependencies listed in Cargo.lock
search Search registry for crates
publish Package and upload this package to the registry
install Install a Rust binary. Default location is $HOME/.cargo/bin
uninstall Uninstall a Rust binary
See 'cargo help ' for more information on a specific command.
cargo 提供的命令
正如上面 cargo 帮助信息中所描述的那样,如果我们想要查看 cargo 提供的所有命令,可以直接在终端里输入
cargo --list
输出结果如下
Installed Commands:
bench Execute all benchmarks of a local p