CARGO(1)
CARGO(1) β General Commands Manual, and bestie, it's the Rust package manager π
π NAME π
cargo β the Rust package manager, aka your new bestie who handles literally everything π
β¨ SYNOPSIS β¨
cargo [options] command [args]
cargo [options] --version
cargo [options] --list
cargo [options] --help
cargo [options] --explain code
π¦ DESCRIPTION π¦
okay so. this program is a package manager and a build tool for the Rust language, and it lives at <https://rust-lang.org>. that's it, that's the vibe. it's giving "I do it all and I make it look easy" π
π COMMANDS π
πΈ Build Commands
cargo-bench(1)β runs the benchmarks of a package. numbers go brrr πcargo-build(1)β compiles a package. the classic.cargo-check(1)β checks a local package and all its dependencies for errors, without doing the whole compile thing.cargo-clean(1)β deletes the artifacts Cargo made earlier. clearing the cache, literally.cargo-doc(1)β builds a package's documentation πcargo-fetch(1)β goes and fetches a package's dependencies from the network.cargo-fix(1)β automatically fixes lint warnings thatrustcreported. glow up, but automated β¨cargo-run(1)β runs a binary or example from the local package πcargo-rustc(1)β compiles a package, but also passes extra options to the compiler.cargo-rustdoc(1)β builds a package's documentation using whatever custom flags you specify.cargo-test(1)β runs a package's unit and integration tests. the moment of truth π«£
π§ Manifest Commands
cargo-add(1)β adds dependencies to aCargo.tomlmanifest file.cargo-generate-lockfile(1)β generatesCargo.lockfor a project.cargo-info(1)β displays info about a package in the registry. the default registry is crates.io.cargo-locate-project(1)β prints a JSON representation of where aCargo.tomlfile is.cargo-metadata(1)β outputs the resolved dependencies of a package in machine-readable format.cargo-pkgid(1)β prints a fully qualified package specification.cargo-remove(1)β removes dependencies from aCargo.tomlmanifest file.cargo-tree(1)β displays a tree visualization of a dependency graph π³cargo-update(1)β updates dependencies as recorded in the local lock file.cargo-vendor(1)β vendors all dependencies locally.
π Package Commands
cargo-init(1)β creates a new Cargo package inside a directory you already have.cargo-install(1)β builds and installs a Rust binary.cargo-new(1)β creates a brand new Cargo package β¨cargo-search(1)β searches for packages in crates.io πcargo-uninstall(1)β removes a Rust binary.
π Publishing Commands
cargo-login(1)β saves an API token from the registry locally.cargo-logout(1)β removes an API token from the registry locally.cargo-owner(1)β manages the owners of a crate on the registry.cargo-package(1)β assembles the local package into a distributable tarball π¦cargo-publish(1)β uploads a package to the registry. main character moment, fr fr.cargo-yank(1)β removes a pushed crate from the index.
π General Commands
cargo-help(1)β displays help information about Cargo.cargo-version(1)β shows version information.
π OPTIONS π
β Special Options
-V,--versionβ prints version info and exits. if you use it with--verbose, it prints extra information.--listβ lists all installed Cargo subcommands. if you use it with--verbose, it prints extra information.--explain codeβ runsrustc --explain CODE, which prints out a detailed explanation of an error message (for example,E0004).
π Display Options
-v,--verboseβ use verbose output. you can specify it twice for "very verbose" output, which includes extra output such as dependency warnings and build script output. may also be specified with theterm.verboseconfig value at <https://doc.rust-lang.org/cargo/reference/config.html>.-q,--quietβ do not print cargo log messages. may also be specified with theterm.quietconfig value at <https://doc.rust-lang.org/cargo/reference/config.html>.--color whenβ controls when colored output is used. valid values are:auto(the default): automatically detect if color support is available on the terminal.always: always display colors.never: never display colors.
may also be specified with the term.color config value at <https://doc.rust-lang.org/cargo/reference/config.html>.
π¦ Manifest Options
--lockedβ asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile was originally generated. Cargo will exit with an error when either of these scenarios arises:- The lock file is missing.
- Cargo attempted to change the lock file due to a different dependency resolution.
it may be used in environments where deterministic builds are desired, such as in CI pipelines.
--offlineβ prevents Cargo from accessing the network for any reason. without this flag, Cargo will stop with an error if it needs to access the network and the network is not available. with this flag, Cargo will attempt to proceed without the network if possible.
beware bestie β this may result in different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. see the cargo-fetch(1) command to download dependencies before going offline.
may also be specified with the net.offline config value at <https://doc.rust-lang.org/cargo/reference/config.html>.
--frozenβ equivalent to specifying both--lockedand--offlineat the same time. two-for-one π
π«Ά Common Options
+toolchainβ if Cargo has been installed with rustup, and the first argument tocargobegins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). see the rustup documentation at <https://rust-lang.github.io/rustup/overrides.html> for more information about how toolchain overrides work.--config KEY=VALUEorPATHβ overrides a Cargo configuration value. the argument should be in TOML syntax ofKEY=VALUE, or provided as a path to an extra configuration file. this flag may be specified multiple times. see the command-line overrides section at <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more information.-C PATHβ changes the current working directory before executing any specified operations. this affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering.cargo/config.toml, for example. this option must appear before the command name, for examplecargo -C path/to/my-project build.
this option is only available on the nightly channel at <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z unstable-options flag to enable (see #10098 at <https://github.com/rust-lang/cargo/issues/10098>).
-h,--helpβ prints help information.-Z flagβ unstable (nightly-only) flags to Cargo. runcargo -Z helpfor details.
πΈ ENVIRONMENT πΈ
see the reference at <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on the environment variables that Cargo reads. iykyk π±
π EXIT STATUS π
0: Cargo succeeded. we love to see it π101: Cargo failed to complete. π
π FILES π
~/.cargo/β the default location for Cargo's "home" directory, where it stores various files. the location can be changed with theCARGO_HOMEenvironment variable.$CARGO_HOME/bin/β binaries installed bycargo-install(1)will be located here. if you're using rustup at <https://rust-lang.github.io/rustup/>, executables distributed with Rust are also located here.$CARGO_HOME/config.tomlβ the global configuration file. see the reference at <https://doc.rust-lang.org/cargo/reference/config.html> for more information about configuration files..cargo/config.tomlβ Cargo automatically searches for a file named.cargo/config.tomlin the current directory, and all parent directories. these configuration files will be merged with the global configuration file.$CARGO_HOME/credentials.tomlβ private authentication information for logging in to a registry π$CARGO_HOME/registry/β this directory contains cached downloads of the registry index and any downloaded dependencies.$CARGO_HOME/git/β this directory contains cached downloads of git dependencies.
heads up bestie: please note that the internal structure of the $CARGO_HOME directory is not stable yet and may be subject to change. don't get too attached π
β EXAMPLES β
- Build a local package and all of its dependencies:
cargo build
- Build a package with optimizations:
cargo build --release
- Run tests for a cross-compiled target:
cargo test --target i686-unknown-linux-gnu
- Create a new package that builds an executable:
cargo new foobar
- Create a package in the current directory:
mkdir foo && cd foo
cargo init .
- Learn about a command's options and usage:
cargo help clean
π BUGS π
see <https://github.com/rust-lang/cargo/issues> for issues. (not me manifesting a bug-free build π―οΈ)
π SEE ALSO π
and that's the whole page, bestie β this was CARGO(1) from the General Commands Manual section, closing out with its very own CARGO(1) footer tag. go build something iconic π«Άπ
π¦ where this page comes from
- ubuntu jammy: cargo-1.85 1.85.1+dfsg0ubuntu2~bpo0-0ubuntu1.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.85 1.85.1+dfsg0ubuntu2~bpo0-0ubuntu0.24.04.2 Β· Apache-2.0 WITH LLVM exception
- ubuntu questing: cargo-1.85 1.85.1+dfsg0ubuntu2-0ubuntu1
- ubuntu questing: cargo-1.85 1.85.1+dfsg0ubuntu2-0ubuntu1.25.04.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms