1CARGO(1) General Commands Manual CARGO(1)
2
3
4
6 cargo - The Rust package manager
7
9 cargo [options] command [args]
10 cargo [options] --version
11 cargo [options] --list
12 cargo [options] --help
13 cargo [options] --explain code
14
16 This program is a package manager and build tool for the Rust language,
17 available at <https://rust-lang.org>.
18
20 Build Commands
21 cargo-bench(1)
22 Execute benchmarks of a package.
23
24 cargo-build(1)
25 Compile a package.
26
27 cargo-check(1)
28 Check a local package and all of its dependencies for errors.
29
30 cargo-clean(1)
31 Remove artifacts that Cargo has generated in the past.
32
33 cargo-doc(1)
34 Build a package's documentation.
35
36 cargo-fetch(1)
37 Fetch dependencies of a package from the network.
38
39 cargo-fix(1)
40 Automatically fix lint warnings reported by rustc.
41
42 cargo-run(1)
43 Run a binary or example of the local package.
44
45 cargo-rustc(1)
46 Compile a package, and pass extra options to the compiler.
47
48 cargo-rustdoc(1)
49 Build a package's documentation, using specified custom flags.
50
51 cargo-test(1)
52 Execute unit and integration tests of a package.
53
54 Manifest Commands
55 cargo-generate-lockfile(1)
56 Generate Cargo.lock for a project.
57
58 cargo-locate-project(1)
59 Print a JSON representation of a Cargo.toml file's location.
60
61 cargo-metadata(1)
62 Output the resolved dependencies of a package in machine-readable
63 format.
64
65 cargo-pkgid(1)
66 Print a fully qualified package specification.
67
68 cargo-tree(1)
69 Display a tree visualization of a dependency graph.
70
71 cargo-update(1)
72 Update dependencies as recorded in the local lock file.
73
74 cargo-vendor(1)
75 Vendor all dependencies locally.
76
77 cargo-verify-project(1)
78 Check correctness of crate manifest.
79
80 Package Commands
81 cargo-init(1)
82 Create a new Cargo package in an existing directory.
83
84 cargo-install(1)
85 Build and install a Rust binary.
86
87 cargo-new(1)
88 Create a new Cargo package.
89
90 cargo-search(1)
91 Search packages in crates.io.
92
93 cargo-uninstall(1)
94 Remove a Rust binary.
95
96 Publishing Commands
97 cargo-login(1)
98 Save an API token from the registry locally.
99
100 cargo-owner(1)
101 Manage the owners of a crate on the registry.
102
103 cargo-package(1)
104 Assemble the local package into a distributable tarball.
105
106 cargo-publish(1)
107 Upload a package to the registry.
108
109 cargo-yank(1)
110 Remove a pushed crate from the index.
111
112 General Commands
113 cargo-help(1)
114 Display help information about Cargo.
115
116 cargo-version(1)
117 Show version information.
118
120 Special Options
121 -V, --version
122 Print version info and exit. If used with --verbose, prints extra
123 information.
124
125 --list
126 List all installed Cargo subcommands. If used with --verbose,
127 prints extra information.
128
129 --explain code
130 Run rustc --explain CODE which will print out a detailed
131 explanation of an error message (for example, E0004).
132
133 Display Options
134 -v, --verbose
135 Use verbose output. May be specified twice for "very verbose"
136 output which includes extra output such as dependency warnings and
137 build script output. May also be specified with the term.verbose
138 config value
139 <https://doc.rust-lang.org/cargo/reference/config.html>.
140
141 -q, --quiet
142 No output printed to stdout.
143
144 --color when
145 Control when colored output is used. Valid values:
146
147 · auto (default): Automatically detect if color support is
148 available on the terminal.
149
150 · always: Always display colors.
151
152 · never: Never display colors.
153
154 May also be specified with the term.color config value
155 <https://doc.rust-lang.org/cargo/reference/config.html>.
156
157 Manifest Options
158 --frozen, --locked
159 Either of these flags requires that the Cargo.lock file is
160 up-to-date. If the lock file is missing, or it needs to be updated,
161 Cargo will exit with an error. The --frozen flag also prevents
162 Cargo from attempting to access the network to determine if it is
163 out-of-date.
164
165 These may be used in environments where you want to assert that the
166 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
167 network access.
168
169 --offline
170 Prevents Cargo from accessing the network for any reason. Without
171 this flag, Cargo will stop with an error if it needs to access the
172 network and the network is not available. With this flag, Cargo
173 will attempt to proceed without the network if possible.
174
175 Beware that this may result in different dependency resolution than
176 online mode. Cargo will restrict itself to crates that are
177 downloaded locally, even if there might be a newer version as
178 indicated in the local copy of the index. See the cargo-fetch(1)
179 command to download dependencies before going offline.
180
181 May also be specified with the net.offline config value
182 <https://doc.rust-lang.org/cargo/reference/config.html>.
183
184 Common Options
185 +toolchain
186 If Cargo has been installed with rustup, and the first argument to
187 cargo begins with +, it will be interpreted as a rustup toolchain
188 name (such as +stable or +nightly). See the rustup documentation
189 <https://rust-lang.github.io/rustup/overrides.html> for more
190 information about how toolchain overrides work.
191
192 -h, --help
193 Prints help information.
194
195 -Z flag
196 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
197 details.
198
200 See the reference
201 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
202 for details on environment variables that Cargo reads.
203
205 · 0: Cargo succeeded.
206
207 · 101: Cargo failed to complete.
208
210 ~/.cargo/
211 Default location for Cargo's "home" directory where it stores
212 various files. The location can be changed with the CARGO_HOME
213 environment variable.
214
215 $CARGO_HOME/bin/
216 Binaries installed by cargo-install(1) will be located here. If
217 using rustup <https://rust-lang.github.io/rustup/>, executables
218 distributed with Rust are also located here.
219
220 $CARGO_HOME/config.toml
221 The global configuration file. See the reference
222 <https://doc.rust-lang.org/cargo/reference/config.html> for more
223 information about configuration files.
224
225 .cargo/config.toml
226 Cargo automatically searches for a file named .cargo/config.toml in
227 the current directory, and all parent directories. These configuration
228 files will be merged with the global configuration file.
229
230 $CARGO_HOME/credentials.toml
231 Private authentication information for logging in to a registry.
232
233 $CARGO_HOME/registry/
234 This directory contains cached downloads of the registry index and
235 any downloaded dependencies.
236
237 $CARGO_HOME/git/
238 This directory contains cached downloads of git dependencies.
239
240 Please note that the internal structure of the $CARGO_HOME directory is
241 not stable yet and may be subject to change.
242
244 1. Build a local package and all of its dependencies:
245
246 cargo build
247
248 2. Build a package with optimizations:
249
250 cargo build --release
251
252 3. Run tests for a cross-compiled target:
253
254 cargo test --target i686-unknown-linux-gnu
255
256 4. Create a new package that builds an executable:
257
258 cargo new foobar
259
260 5. Create a package in the current directory:
261
262 mkdir foo && cd foo
263 cargo init .
264
265 6. Learn about a command's options and usage:
266
267 cargo help clean
268
270 See <https://github.com/rust-lang/cargo/issues> for issues.
271
273 rustc(1), rustdoc(1)
274
275
276
277 CARGO(1)