8 cargo-fetch - Fetch dependencies of a package from the network
12 `cargo fetch` [_options_]
16 If a `Cargo.lock` file is available, this command will ensure that all of the
17 git dependencies and/or registry dependencies are downloaded and locally
18 available. Subsequent Cargo commands will be able to run offline after a `cargo
19 fetch` unless the lock file changes.
21 If the lock file is not available, then this command will generate the lock
22 file before fetching the dependencies.
24 If `--target` is not specified, then all target dependencies are fetched.
26 See also the [cargo-prefetch](https://crates.io/crates/cargo-prefetch)
27 plugin which adds a command to download popular crates. This may be useful if
28 you plan to use Cargo without a network with the `--offline` flag.
35 <dt class="option-term" id="option-cargo-fetch---target"><a class="option-anchor" href="#option-cargo-fetch---target"></a><code>--target</code> <em>triple</em></dt>
36 <dd class="option-desc">Fetch for the given architecture. The default is all architectures. The general format of the triple is
37 <code><arch><sub>-<vendor>-<sys>-<abi></code>. Run <code>rustc --print target-list</code> for a
38 list of supported targets. This flag may be specified multiple times.</p>
39 <p>This may also be specified with the <code>build.target</code>
40 <a href="../reference/config.html">config value</a>.</p>
41 <p>Note that specifying this flag makes Cargo run in a different mode where the
42 target artifacts are placed in a separate directory. See the
43 <a href="../guide/build-cache.html">build cache</a> documentation for more details.</dd>
51 <dt class="option-term" id="option-cargo-fetch--v"><a class="option-anchor" href="#option-cargo-fetch--v"></a><code>-v</code></dt>
52 <dt class="option-term" id="option-cargo-fetch---verbose"><a class="option-anchor" href="#option-cargo-fetch---verbose"></a><code>--verbose</code></dt>
53 <dd class="option-desc">Use verbose output. May be specified twice for "very verbose" output which
54 includes extra output such as dependency warnings and build script output.
55 May also be specified with the <code>term.verbose</code>
56 <a href="../reference/config.html">config value</a>.</dd>
59 <dt class="option-term" id="option-cargo-fetch--q"><a class="option-anchor" href="#option-cargo-fetch--q"></a><code>-q</code></dt>
60 <dt class="option-term" id="option-cargo-fetch---quiet"><a class="option-anchor" href="#option-cargo-fetch---quiet"></a><code>--quiet</code></dt>
61 <dd class="option-desc">Do not print cargo log messages.
62 May also be specified with the <code>term.quiet</code>
63 <a href="../reference/config.html">config value</a>.</dd>
66 <dt class="option-term" id="option-cargo-fetch---color"><a class="option-anchor" href="#option-cargo-fetch---color"></a><code>--color</code> <em>when</em></dt>
67 <dd class="option-desc">Control when colored output is used. Valid values:</p>
69 <li><code>auto</code> (default): Automatically detect if color support is available on the
71 <li><code>always</code>: Always display colors.</li>
72 <li><code>never</code>: Never display colors.</li>
74 <p>May also be specified with the <code>term.color</code>
75 <a href="../reference/config.html">config value</a>.</dd>
83 <dt class="option-term" id="option-cargo-fetch---manifest-path"><a class="option-anchor" href="#option-cargo-fetch---manifest-path"></a><code>--manifest-path</code> <em>path</em></dt>
84 <dd class="option-desc">Path to the <code>Cargo.toml</code> file. By default, Cargo searches for the
85 <code>Cargo.toml</code> file in the current directory or any parent directory.</dd>
89 <dt class="option-term" id="option-cargo-fetch---frozen"><a class="option-anchor" href="#option-cargo-fetch---frozen"></a><code>--frozen</code></dt>
90 <dt class="option-term" id="option-cargo-fetch---locked"><a class="option-anchor" href="#option-cargo-fetch---locked"></a><code>--locked</code></dt>
91 <dd class="option-desc">Either of these flags requires that the <code>Cargo.lock</code> file is
92 up-to-date. If the lock file is missing, or it needs to be updated, Cargo will
93 exit with an error. The <code>--frozen</code> flag also prevents Cargo from
94 attempting to access the network to determine if it is out-of-date.</p>
95 <p>These may be used in environments where you want to assert that the
96 <code>Cargo.lock</code> file is up-to-date (such as a CI build) or want to avoid network
100 <dt class="option-term" id="option-cargo-fetch---offline"><a class="option-anchor" href="#option-cargo-fetch---offline"></a><code>--offline</code></dt>
101 <dd class="option-desc">Prevents Cargo from accessing the network for any reason. Without this
102 flag, Cargo will stop with an error if it needs to access the network and
103 the network is not available. With this flag, Cargo will attempt to
104 proceed without the network if possible.</p>
105 <p>Beware that this may result in different dependency resolution than online
106 mode. Cargo will restrict itself to crates that are downloaded locally, even
107 if there might be a newer version as indicated in the local copy of the index.
108 See the <a href="cargo-fetch.html">cargo-fetch(1)</a> command to download dependencies before going
110 <p>May also be specified with the <code>net.offline</code> <a href="../reference/config.html">config value</a>.</dd>
119 <dt class="option-term" id="option-cargo-fetch-+toolchain"><a class="option-anchor" href="#option-cargo-fetch-+toolchain"></a><code>+</code><em>toolchain</em></dt>
120 <dd class="option-desc">If Cargo has been installed with rustup, and the first argument to <code>cargo</code>
121 begins with <code>+</code>, it will be interpreted as a rustup toolchain name (such
122 as <code>+stable</code> or <code>+nightly</code>).
123 See the <a href="https://rust-lang.github.io/rustup/overrides.html">rustup documentation</a>
124 for more information about how toolchain overrides work.</dd>
127 <dt class="option-term" id="option-cargo-fetch---config"><a class="option-anchor" href="#option-cargo-fetch---config"></a><code>--config</code> <em>KEY=VALUE</em> or <em>PATH</em></dt>
128 <dd class="option-desc">Overrides a Cargo configuration value. The argument should be in TOML syntax of <code>KEY=VALUE</code>,
129 or provided as a path to an extra configuration file. This flag may be specified multiple times.
130 See the <a href="../reference/config.html#command-line-overrides">command-line overrides section</a> for more information.</dd>
133 <dt class="option-term" id="option-cargo-fetch--h"><a class="option-anchor" href="#option-cargo-fetch--h"></a><code>-h</code></dt>
134 <dt class="option-term" id="option-cargo-fetch---help"><a class="option-anchor" href="#option-cargo-fetch---help"></a><code>--help</code></dt>
135 <dd class="option-desc">Prints help information.</dd>
138 <dt class="option-term" id="option-cargo-fetch--Z"><a class="option-anchor" href="#option-cargo-fetch--Z"></a><code>-Z</code> <em>flag</em></dt>
139 <dd class="option-desc">Unstable (nightly-only) flags to Cargo. Run <code>cargo -Z help</code> for details.</dd>
147 See [the reference](../reference/environment-variables.html) for
148 details on environment variables that Cargo reads.
153 * `0`: Cargo succeeded.
154 * `101`: Cargo failed to complete.
159 1. Fetch all dependencies:
164 [cargo(1)](cargo.html), [cargo-update(1)](cargo-update.html), [cargo-generate-lockfile(1)](cargo-generate-lockfile.html)