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 No output printed to stdout.
69
70 --color when
71 Control when colored output is used. Valid values:
72
73 • auto (default): Automatically detect if color support is
74 available on the terminal.
75
76 • always: Always display colors.
77
78 • never: Never display colors.
79
80 May also be specified with the term.color config value
81 <https://doc.rust-lang.org/cargo/reference/config.html>.
82
83 Common Options
84 +toolchain
85 If Cargo has been installed with rustup, and the first argument to
86 cargo begins with +, it will be interpreted as a rustup toolchain
87 name (such as +stable or +nightly). See the rustup documentation
88 <https://rust-lang.github.io/rustup/overrides.html> for more
89 information about how toolchain overrides work.
90
91 -h, --help
92 Prints help information.
93
94 -Z flag
95 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
96 details.
97
99 See the reference
100 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
101 for details on environment variables that Cargo reads.
102
104 • 0: Cargo succeeded.
105
106 • 101: Cargo failed to complete.
107
109 1. Create a binary Cargo package in the current directory:
110
111 cargo init
112
114 cargo(1), cargo-new(1)
115
116
117
118 CARGO-INIT(1)