5 cargo-init --- Create a new Cargo package in an existing directory
9 `cargo init` [_options_] [_path_]
13 This command will create a new Cargo manifest in the current directory. Give a
14 path as an argument to create in the given directory.
16 If there are typically-named Rust source files already in the directory, those
17 will be used. If not, then a sample `src/main.rs` file will be created, or
18 `src/lib.rs` if `--lib` is passed.
20 If the directory is not already in a VCS repository, then a new repository
21 is created (see `--vcs` below).
23 See [cargo-new(1)](cargo-new.html) for a similar command which will create a new package in
32 <dt class="option-term" id="option-cargo-init---bin"><a class="option-anchor" href="#option-cargo-init---bin"></a><code>--bin</code></dt>
33 <dd class="option-desc">Create a package with a binary target (<code>src/main.rs</code>).
34 This is the default behavior.</dd>
37 <dt class="option-term" id="option-cargo-init---lib"><a class="option-anchor" href="#option-cargo-init---lib"></a><code>--lib</code></dt>
38 <dd class="option-desc">Create a package with a library target (<code>src/lib.rs</code>).</dd>
41 <dt class="option-term" id="option-cargo-init---edition"><a class="option-anchor" href="#option-cargo-init---edition"></a><code>--edition</code> <em>edition</em></dt>
42 <dd class="option-desc">Specify the Rust edition to use. Default is 2021.
43 Possible values: 2015, 2018, 2021</dd>
46 <dt class="option-term" id="option-cargo-init---name"><a class="option-anchor" href="#option-cargo-init---name"></a><code>--name</code> <em>name</em></dt>
47 <dd class="option-desc">Set the package name. Defaults to the directory name.</dd>
50 <dt class="option-term" id="option-cargo-init---vcs"><a class="option-anchor" href="#option-cargo-init---vcs"></a><code>--vcs</code> <em>vcs</em></dt>
51 <dd class="option-desc">Initialize a new VCS repository for the given version control system (git,
52 hg, pijul, or fossil) or do not initialize any version control at all
53 (none). If not specified, defaults to <code>git</code> or the configuration value
54 <code>cargo-new.vcs</code>, or <code>none</code> if already inside a VCS repository.</dd>
57 <dt class="option-term" id="option-cargo-init---registry"><a class="option-anchor" href="#option-cargo-init---registry"></a><code>--registry</code> <em>registry</em></dt>
58 <dd class="option-desc">This sets the <code>publish</code> field in <code>Cargo.toml</code> to the given registry name
59 which will restrict publishing only to that registry.</p>
60 <p>Registry names are defined in <a href="../reference/config.html">Cargo config files</a>.
61 If not specified, the default registry defined by the <code>registry.default</code>
62 config key is used. If the default registry is not set and <code>--registry</code> is not
63 used, the <code>publish</code> field will not be set which means that publishing will not
73 <dt class="option-term" id="option-cargo-init--v"><a class="option-anchor" href="#option-cargo-init--v"></a><code>-v</code></dt>
74 <dt class="option-term" id="option-cargo-init---verbose"><a class="option-anchor" href="#option-cargo-init---verbose"></a><code>--verbose</code></dt>
75 <dd class="option-desc">Use verbose output. May be specified twice for “very verbose” output which
76 includes extra output such as dependency warnings and build script output.
77 May also be specified with the <code>term.verbose</code>
78 <a href="../reference/config.html">config value</a>.</dd>
81 <dt class="option-term" id="option-cargo-init--q"><a class="option-anchor" href="#option-cargo-init--q"></a><code>-q</code></dt>
82 <dt class="option-term" id="option-cargo-init---quiet"><a class="option-anchor" href="#option-cargo-init---quiet"></a><code>--quiet</code></dt>
83 <dd class="option-desc">Do not print cargo log messages.
84 May also be specified with the <code>term.quiet</code>
85 <a href="../reference/config.html">config value</a>.</dd>
88 <dt class="option-term" id="option-cargo-init---color"><a class="option-anchor" href="#option-cargo-init---color"></a><code>--color</code> <em>when</em></dt>
89 <dd class="option-desc">Control when colored output is used. Valid values:</p>
91 <li><code>auto</code> (default): Automatically detect if color support is available on the
93 <li><code>always</code>: Always display colors.</li>
94 <li><code>never</code>: Never display colors.</li>
96 <p>May also be specified with the <code>term.color</code>
97 <a href="../reference/config.html">config value</a>.</dd>
106 <dt class="option-term" id="option-cargo-init-+toolchain"><a class="option-anchor" href="#option-cargo-init-+toolchain"></a><code>+</code><em>toolchain</em></dt>
107 <dd class="option-desc">If Cargo has been installed with rustup, and the first argument to <code>cargo</code>
108 begins with <code>+</code>, it will be interpreted as a rustup toolchain name (such
109 as <code>+stable</code> or <code>+nightly</code>).
110 See the <a href="https://rust-lang.github.io/rustup/overrides.html">rustup documentation</a>
111 for more information about how toolchain overrides work.</dd>
114 <dt class="option-term" id="option-cargo-init---config"><a class="option-anchor" href="#option-cargo-init---config"></a><code>--config</code> <em>KEY=VALUE</em> or <em>PATH</em></dt>
115 <dd class="option-desc">Overrides a Cargo configuration value. The argument should be in TOML syntax of <code>KEY=VALUE</code>,
116 or provided as a path to an extra configuration file. This flag may be specified multiple times.
117 See the <a href="../reference/config.html#command-line-overrides">command-line overrides section</a> for more information.</dd>
120 <dt class="option-term" id="option-cargo-init--C"><a class="option-anchor" href="#option-cargo-init--C"></a><code>-C</code> <em>PATH</em></dt>
121 <dd class="option-desc">Changes the current working directory before executing any specified operations. This affects
122 things like where cargo looks by default for the project manifest (<code>Cargo.toml</code>), as well as
123 the directories searched for discovering <code>.cargo/config.toml</code>, for example. This option must
124 appear before the command name, for example <code>cargo -C path/to/my-project build</code>.</p>
125 <p>This option is only available on the <a href="https://doc.rust-lang.org/book/appendix-07-nightly-rust.html">nightly
127 requires the <code>-Z unstable-options</code> flag to enable (see
128 <a href="https://github.com/rust-lang/cargo/issues/10098">#10098</a>).</dd>
131 <dt class="option-term" id="option-cargo-init--h"><a class="option-anchor" href="#option-cargo-init--h"></a><code>-h</code></dt>
132 <dt class="option-term" id="option-cargo-init---help"><a class="option-anchor" href="#option-cargo-init---help"></a><code>--help</code></dt>
133 <dd class="option-desc">Prints help information.</dd>
136 <dt class="option-term" id="option-cargo-init--Z"><a class="option-anchor" href="#option-cargo-init--Z"></a><code>-Z</code> <em>flag</em></dt>
137 <dd class="option-desc">Unstable (nightly-only) flags to Cargo. Run <code>cargo -Z help</code> for details.</dd>
145 See [the reference](../reference/environment-variables.html) for
146 details on environment variables that Cargo reads.
151 * `0`: Cargo succeeded.
152 * `101`: Cargo failed to complete.
157 1. Create a binary Cargo package in the current directory:
162 [cargo(1)](cargo.html), [cargo-new(1)](cargo-new.html)