1CARGO-INSTALL(1) General Commands Manual CARGO-INSTALL(1)
2
3
4
6 cargo-install - Build and install a Rust binary
7
9 cargo install [options] crate...
10 cargo install [options] --path path
11 cargo install [options] --git url [crate...]
12 cargo install [options] --list
13
15 This command manages Cargo's local set of installed binary crates. Only
16 packages which have executable [[bin]] or [[example]] targets can be
17 installed, and all executables are installed into the installation
18 root's bin folder.
19
20 The installation root is determined, in order of precedence:
21
22 · --root option
23
24 · CARGO_INSTALL_ROOT environment variable
25
26 · install.root Cargo config value
27 <https://doc.rust-lang.org/cargo/reference/config.html>
28
29 · CARGO_HOME environment variable
30
31 · $HOME/.cargo
32
33 There are multiple sources from which a crate can be installed. The
34 default location is crates.io but the --git, --path, and --registry
35 flags can change this source. If the source contains more than one
36 package (such as crates.io or a git repository with multiple crates)
37 the crate argument is required to indicate which crate should be
38 installed.
39
40 Crates from crates.io can optionally specify the version they wish to
41 install via the --version flags, and similarly packages from git
42 repositories can optionally specify the branch, tag, or revision that
43 should be installed. If a crate has multiple binaries, the --bin
44 argument can selectively install only one of them, and if you'd rather
45 install examples the --example argument can be used as well.
46
47 If the package is already installed, Cargo will reinstall it if the
48 installed version does not appear to be up-to-date. If any of the
49 following values change, then Cargo will reinstall the package:
50
51 · The package version and source.
52
53 · The set of binary names installed.
54
55 · The chosen features.
56
57 · The release mode (--debug).
58
59 · The target (--target).
60
61 Installing with --path will always build and install, unless there are
62 conflicting binaries from another package. The --force flag may be used
63 to force Cargo to always reinstall the package.
64
65 If the source is crates.io or --git then by default the crate will be
66 built in a temporary target directory. To avoid this, the target
67 directory can be specified by setting the CARGO_TARGET_DIR environment
68 variable to a relative path. In particular, this can be useful for
69 caching build artifacts on continuous integration systems.
70
71 By default, the Cargo.lock file that is included with the package will
72 be ignored. This means that Cargo will recompute which versions of
73 dependencies to use, possibly using newer versions that have been
74 released since the package was published. The --locked flag can be used
75 to force Cargo to use the packaged Cargo.lock file if it is available.
76 This may be useful for ensuring reproducible builds, to use the exact
77 same set of dependencies that were available when the package was
78 published. It may also be useful if a newer version of a dependency is
79 published that no longer builds on your system, or has other problems.
80 The downside to using --locked is that you will not receive any fixes
81 or updates to any dependency. Note that Cargo did not start publishing
82 Cargo.lock files until version 1.37, which means packages published
83 with prior versions will not have a Cargo.lock file available.
84
86 Install Options
87 --vers version, --version version
88 Specify a version to install. This may be a version requirement
89 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.md>,
90 like ~1.2, to have Cargo select the newest version from the given
91 requirement. If the version does not have a requirement operator
92 (such as ^ or ~), then it must be in the form MAJOR.MINOR.PATCH,
93 and will install exactly that version; it is not treated as a caret
94 requirement like Cargo dependencies are.
95
96 --git url
97 Git URL to install the specified crate from.
98
99 --branch branch
100 Branch to use when installing from git.
101
102 --tag tag
103 Tag to use when installing from git.
104
105 --rev sha
106 Specific commit to use when installing from git.
107
108 --path path
109 Filesystem path to local crate to install.
110
111 --list
112 List all installed packages and their versions.
113
114 -f, --force
115 Force overwriting existing crates or binaries. This can be used if
116 a package has installed a binary with the same name as another
117 package. This is also useful if something has changed on the system
118 that you want to rebuild with, such as a newer version of rustc.
119
120 --no-track
121 By default, Cargo keeps track of the installed packages with a
122 metadata file stored in the installation root directory. This flag
123 tells Cargo not to use or create that file. With this flag, Cargo
124 will refuse to overwrite any existing files unless the --force flag
125 is used. This also disables Cargo's ability to protect against
126 multiple concurrent invocations of Cargo installing at the same
127 time.
128
129 --bin name...
130 Install only the specified binary.
131
132 --bins
133 Install all binaries.
134
135 --example name...
136 Install only the specified example.
137
138 --examples
139 Install all examples.
140
141 --root dir
142 Directory to install packages into.
143
144 --registry registry
145 Name of the registry to use. Registry names are defined in Cargo
146 config files
147 <https://doc.rust-lang.org/cargo/reference/config.html>. If not
148 specified, the default registry is used, which is defined by the
149 registry.default config key which defaults to crates-io.
150
151 --index index
152 The URL of the registry index to use.
153
154 Feature Selection
155 The feature flags allow you to control which features are enabled. When
156 no feature options are given, the default feature is activated for
157 every selected package.
158
159 See the features documentation
160 <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
161 for more details.
162
163 --features features
164 Space or comma separated list of features to activate. Features of
165 workspace members may be enabled with package-name/feature-name
166 syntax. This flag may be specified multiple times, which enables
167 all specified features.
168
169 --all-features
170 Activate all available features of all selected packages.
171
172 --no-default-features
173 Do not activate the default feature of the selected packages.
174
175 Compilation Options
176 --target triple
177 Install for the given architecture. The default is the host
178 architecture. The general format of the triple is
179 <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
180 a list of supported targets.
181
182 This may also be specified with the build.target config value
183 <https://doc.rust-lang.org/cargo/reference/config.html>.
184
185 Note that specifying this flag makes Cargo run in a different mode
186 where the target artifacts are placed in a separate directory. See
187 the build cache
188 <https://doc.rust-lang.org/cargo/guide/build-cache.html>
189 documentation for more details.
190
191 --target-dir directory
192 Directory for all generated artifacts and intermediate files. May
193 also be specified with the CARGO_TARGET_DIR environment variable,
194 or the build.target-dir config value
195 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
196 to target in the root of the workspace.
197
198 --debug
199 Build with the dev profile instead the release profile.
200
201 Manifest Options
202 --frozen, --locked
203 Either of these flags requires that the Cargo.lock file is
204 up-to-date. If the lock file is missing, or it needs to be updated,
205 Cargo will exit with an error. The --frozen flag also prevents
206 Cargo from attempting to access the network to determine if it is
207 out-of-date.
208
209 These may be used in environments where you want to assert that the
210 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
211 network access.
212
213 --offline
214 Prevents Cargo from accessing the network for any reason. Without
215 this flag, Cargo will stop with an error if it needs to access the
216 network and the network is not available. With this flag, Cargo
217 will attempt to proceed without the network if possible.
218
219 Beware that this may result in different dependency resolution than
220 online mode. Cargo will restrict itself to crates that are
221 downloaded locally, even if there might be a newer version as
222 indicated in the local copy of the index. See the cargo-fetch(1)
223 command to download dependencies before going offline.
224
225 May also be specified with the net.offline config value
226 <https://doc.rust-lang.org/cargo/reference/config.html>.
227
228 Miscellaneous Options
229 -j N, --jobs N
230 Number of parallel jobs to run. May also be specified with the
231 build.jobs config value
232 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
233 to the number of CPUs.
234
235 Display Options
236 -v, --verbose
237 Use verbose output. May be specified twice for "very verbose"
238 output which includes extra output such as dependency warnings and
239 build script output. May also be specified with the term.verbose
240 config value
241 <https://doc.rust-lang.org/cargo/reference/config.html>.
242
243 -q, --quiet
244 No output printed to stdout.
245
246 --color when
247 Control when colored output is used. Valid values:
248
249 · auto (default): Automatically detect if color support is
250 available on the terminal.
251
252 · always: Always display colors.
253
254 · never: Never display colors.
255
256 May also be specified with the term.color config value
257 <https://doc.rust-lang.org/cargo/reference/config.html>.
258
259 Common Options
260 +toolchain
261 If Cargo has been installed with rustup, and the first argument to
262 cargo begins with +, it will be interpreted as a rustup toolchain
263 name (such as +stable or +nightly). See the rustup documentation
264 <https://rust-lang.github.io/rustup/overrides.html> for more
265 information about how toolchain overrides work.
266
267 -h, --help
268 Prints help information.
269
270 -Z flag
271 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
272 details.
273
275 See the reference
276 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
277 for details on environment variables that Cargo reads.
278
280 · 0: Cargo succeeded.
281
282 · 101: Cargo failed to complete.
283
285 1. Install or upgrade a package from crates.io:
286
287 cargo install ripgrep
288
289 2. Install or reinstall the package in the current directory:
290
291 cargo install --path .
292
293 3. View the list of installed packages:
294
295 cargo install --list
296
298 cargo(1), cargo-uninstall(1), cargo-search(1), cargo-publish(1)
299
300
301
302 CARGO-INSTALL(1)