1CARGO-INIT(1) General Commands Manual CARGO-INIT(1)
2
3
4
6 cargo-init — Create a new Cargo package in an existing directory
7
9 cargo init [options] [path]
10
12 This command will create a new Cargo manifest in the current directory.
13 Give a path as an argument to create in the given directory.
14
15 If there are typically-named Rust source files already in the
16 directory, those will be used. If not, then a sample src/main.rs file
17 will be created, or src/lib.rs if --lib is passed.
18
19 If the directory is not already in a VCS repository, then a new
20 repository is created (see --vcs below).
21
22 See cargo-new(1) for a similar command which will create a new package
23 in a new directory.
24
26 Init Options
27 --bin
28 Create a package with a binary target (src/main.rs). This is the
29 default behavior.
30
31 --lib
32 Create a package with a library target (src/lib.rs).
33
34 --edition edition
35 Specify the Rust edition to use. Default is 2021. Possible values:
36 2015, 2018, 2021
37
38 --name name
39 Set the package name. Defaults to the directory name.
40
41 --vcs vcs
42 Initialize a new VCS repository for the given version control
43 system (git, hg, pijul, or fossil) or do not initialize any version
44 control at all (none). If not specified, defaults to git or the
45 configuration value cargo-new.vcs, or none if already inside a VCS
46 repository.
47
48 --registry registry
49 This sets the publish field in Cargo.toml to the given registry
50 name which will restrict publishing only to that registry.
51
52 Registry names are defined in Cargo config files
53 <https://doc.rust-lang.org/cargo/reference/config.html>. If not
54 specified, the default registry defined by the registry.default
55 config key is used. If the default registry is not set and
56 --registry is not used, the publish field will not be set which
57 means that publishing will not be restricted.
58
59 Display Options
60 -v, --verbose
61 Use verbose output. May be specified twice for “very verbose”
62 output which includes extra output such as dependency warnings and
63 build script output. May also be specified with the term.verbose
64 config value
65 <https://doc.rust-lang.org/cargo/reference/config.html>.
66
67 -q, --quiet
68 Do not print cargo log messages. May also be specified with the
69 term.quiet config value
70 <https://doc.rust-lang.org/cargo/reference/config.html>.
71
72 --color when
73 Control when colored output is used. Valid values:
74
75 • auto (default): Automatically detect if color support is
76 available on the terminal.
77
78 • always: Always display colors.
79
80 • never: Never display colors.
81
82 May also be specified with the term.color config value
83 <https://doc.rust-lang.org/cargo/reference/config.html>.
84
85 Common Options
86 +toolchain
87 If Cargo has been installed with rustup, and the first argument to
88 cargo begins with +, it will be interpreted as a rustup toolchain
89 name (such as +stable or +nightly). See the rustup documentation
90 <https://rust-lang.github.io/rustup/overrides.html> for more
91 information about how toolchain overrides work.
92
93 --config KEY=VALUE or PATH
94 Overrides a Cargo configuration value. The argument should be in
95 TOML syntax of KEY=VALUE, or provided as a path to an extra
96 configuration file. This flag may be specified multiple times. See
97 the command-line overrides section
98 <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
99 for more information.
100
101 -C PATH
102 Changes the current working directory before executing any
103 specified operations. This affects things like where cargo looks by
104 default for the project manifest (Cargo.toml), as well as the
105 directories searched for discovering .cargo/config.toml, for
106 example. This option must appear before the command name, for
107 example cargo -C path/to/my-project build.
108
109 This option is only available on the nightly channel
110 <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
111 requires the -Z unstable-options flag to enable (see #10098
112 <https://github.com/rust-lang/cargo/issues/10098>).
113
114 -h, --help
115 Prints help information.
116
117 -Z flag
118 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
119 details.
120
122 See the reference
123 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
124 for details on environment variables that Cargo reads.
125
127 • 0: Cargo succeeded.
128
129 • 101: Cargo failed to complete.
130
132 1. Create a binary Cargo package in the current directory:
133
134 cargo init
135
137 cargo(1), cargo-new(1)
138
139
140
141 CARGO-INIT(1)