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 -h, --help
94 Prints help information.
95
96 -Z flag
97 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
98 details.
99
101 See the reference
102 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
103 for details on environment variables that Cargo reads.
104
106 • 0: Cargo succeeded.
107
108 • 101: Cargo failed to complete.
109
111 1. Create a binary Cargo package in the current directory:
112
113 cargo init
114
116 cargo(1), cargo-new(1)
117
118
119
120 CARGO-INIT(1)