1CARGO-NEW(1) General Commands Manual CARGO-NEW(1)
2
3
4
6 cargo-new - Create a new Cargo package
7
9 cargo new [options] path
10
12 This command will create a new Cargo package in the given directory.
13 This includes a simple template with a Cargo.toml manifest, sample
14 source file, and a VCS ignore file. If the directory is not already in
15 a VCS repository, then a new repository is created (see --vcs below).
16
17 See cargo-init(1) for a similar command which will create a new
18 manifest in an existing directory.
19
21 New Options
22 --bin
23 Create a package with a binary target (src/main.rs). This is the
24 default behavior.
25
26 --lib
27 Create a package with a library target (src/lib.rs).
28
29 --edition edition
30 Specify the Rust edition to use. Default is 2021. Possible values:
31 2015, 2018, 2021
32
33 --name name
34 Set the package name. Defaults to the directory name.
35
36 --vcs vcs
37 Initialize a new VCS repository for the given version control
38 system (git, hg, pijul, or fossil) or do not initialize any version
39 control at all (none). If not specified, defaults to git or the
40 configuration value cargo-new.vcs, or none if already inside a VCS
41 repository.
42
43 --registry registry
44 This sets the publish field in Cargo.toml to the given registry
45 name which will restrict publishing only to that registry.
46
47 Registry names are defined in Cargo config files
48 <https://doc.rust-lang.org/cargo/reference/config.html>. If not
49 specified, the default registry defined by the registry.default
50 config key is used. If the default registry is not set and
51 --registry is not used, the publish field will not be set which
52 means that publishing will not be restricted.
53
54 Display Options
55 -v, --verbose
56 Use verbose output. May be specified twice for "very verbose"
57 output which includes extra output such as dependency warnings and
58 build script output. May also be specified with the term.verbose
59 config value
60 <https://doc.rust-lang.org/cargo/reference/config.html>.
61
62 -q, --quiet
63 Do not print cargo log messages. May also be specified with the
64 term.quiet config value
65 <https://doc.rust-lang.org/cargo/reference/config.html>.
66
67 --color when
68 Control when colored output is used. Valid values:
69
70 • auto (default): Automatically detect if color support is
71 available on the terminal.
72
73 • always: Always display colors.
74
75 • never: Never display colors.
76
77 May also be specified with the term.color config value
78 <https://doc.rust-lang.org/cargo/reference/config.html>.
79
80 Common Options
81 +toolchain
82 If Cargo has been installed with rustup, and the first argument to
83 cargo begins with +, it will be interpreted as a rustup toolchain
84 name (such as +stable or +nightly). See the rustup documentation
85 <https://rust-lang.github.io/rustup/overrides.html> for more
86 information about how toolchain overrides work.
87
88 -h, --help
89 Prints help information.
90
91 -Z flag
92 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
93 details.
94
96 See the reference
97 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
98 for details on environment variables that Cargo reads.
99
101 • 0: Cargo succeeded.
102
103 • 101: Cargo failed to complete.
104
106 1. Create a binary Cargo package in the given directory:
107
108 cargo new foo
109
111 cargo(1), cargo-init(1)
112
113
114
115 CARGO-NEW(1)