CARGO-FETCH(1)
CARGO-FETCH π (1)
okay bestie, welcome to the General Commands Manual corner of the cargo universe β this is the cargo-fetch page and it's about to be your new fave for hoarding dependencies like they're limited-edition Squishmallows π§Έβ¨
β¨ NAME β¨
cargo-fetch β Fetch dependencies of a package from the network ππ«
πΈ SYNOPSIS πΈ
cargo fetch [options]
π¦ DESCRIPTION π¦
so here's the vibe: if you've got a Cargo.lock file sitting there, this command makes sure every single git dependency and/or registry dependency is downloaded and chillin' locally on your machine. and the slay part? after a cargo fetch, all your future Cargo commands can run offline β unless the lock file changes, in which case, yeah, we're back online babes π
and if the lock file isn't there yet? no stress. this command generates the lock file first, then goes and fetches everything. main character energy fr fr π
if you don't specify --target, then all target dependencies get fetched. all of them. every last one. we're thorough like that π
also!! there's a plugin called cargo-prefetch <https://crates.io/crates/cargo-prefetch> that adds a command to download popular crates. lowkey useful if you're planning to use Cargo without a network using the --offline flag. iykyk π
π OPTIONS π
π Fetch options
--targettriple β Fetch for the given architecture. the default is all architectures. the general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>. runrustc --print target-listfor a list of supported targets. this flag can be specified multiple times (yes queen, stack 'em) β¨
This may also be specified with the build.target config value <https://doc.rust-lang.org/cargo/reference/config.html>.
heads up bestie β οΈ specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. see the build cache <https://doc.rust-lang.org/cargo/guide/build-cache.html> documentation for more details.
π Display Options
-v,--verboseβ Use verbose output. may be specified 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 <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 <https://doc.rust-lang.org/cargo/reference/config.html>. π€«--colorwhen β Control when colored output is used. valid values are:auto(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 <https://doc.rust-lang.org/cargo/reference/config.html>.
π Manifest Options
--manifest-pathpath β Path to theCargo.tomlfile. by default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory. π--frozen,--lockedβ Either of these flags requires that theCargo.lockfile is up-to-date. if the lock file is missing, or it needs to be updated, Cargo will exit with an error. the--frozenflag also prevents Cargo from attempting to access the network to determine if it is out-of-date. π₯Ά
These may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build) or want to avoid network access.
--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.
May also be specified with the net.offline config value <https://doc.rust-lang.org/cargo/reference/config.html>.
π Common Options
+toolchainβ If Cargo has been installed with rustup, and the first argument to cargo begins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). see the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more information about how toolchain overrides work. π οΈ--configKEY=VALUE or PATH β 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 <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more information. βοΈ-CPATH β 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 <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z unstable-options flag to enable (see #10098 <https://github.com/rust-lang/cargo/issues/10098>). π
-h,--helpβ Prints help information. π-Zflag β Unstable (nightly-only) flags to Cargo. runcargo -Z helpfor details. π§ͺ
π ENVIRONMENT π
See the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on environment variables that Cargo reads. π±
π EXIT STATUS π
0: Cargo succeeded. π101: Cargo failed to complete. π
β EXAMPLES β
- Fetch all dependencies:
cargo fetch
π«Ά SEE ALSO π«Ά
cargo(1), cargo-update(1), cargo-generate-lockfile(1)
and that's the whole page, bestie!! cargo-fetch(1) β this page came straight out of the General Commands Manual (that's the source, mwah π), so go forth, fetch those deps, and stay offline-ready. periodt. πβ¨ππ¦πΈ
π¦ where this page comes from
- ubuntu jammy: cargo-1.78 1.78.0+dfsg1ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.78 1.78.0+dfsg1ubuntu1-0ubuntu0.24.04.2 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms