CARGO-NEW(1)
๐ CARGO-NEW(1) ๐
okay bestie, welcome to the General Commands Manual page for cargo-new, section 1, and honestly? it's giving "starter pack but make it official." let's get into it ๐ซถ
โจ NAME โจ
cargo-new โ Create a new Cargo package
like. it makes you a whole new Cargo package. brand new. fresh out the box. ๐ธ
๐ SYNOPSIS ๐
cargo new [options] path
that's it. that's the whole vibe. cargo new, some optional flags, and a path. slay.
๐ฆ DESCRIPTION ๐ฆ
so when you run this command, it creates a new Cargo package in whatever directory you point it at. and not just an empty folder, no no โ it comes with a simple template: a Cargo.toml manifest, a sample source file, and a VCS ignore file. a whole lil starter kit. iconic. โจ
and here's the tea: if the directory is not already inside a VCS repository, then a brand new repository gets created for you (peep --vcs down below to control that ๐).
also, if you want the similar but different version of this โ the one that creates a new manifest inside a directory that already exists โ go check out cargo-init(1). sibling energy fr fr.
๐ OPTIONS ๐
๐ New Options ๐
--binโ create a package with a binary target (src/main.rs). lowkey this is the default behavior, so if you do nothing, you get a binary. main character energy from the jump.--libโ create a package with a library target (src/lib.rs). for when you're in your library era ๐--editionedition โ specify which Rust edition to use. default is2024. possible values:2015,2018,2021,2024. pick your era bestie, there are literally four of them.--namename โ set the package name. if you don't, it defaults to the directory name. no thoughts, just folder name. ๐--vcsvcs โ initialize a new VCS repository for the given version control system. your options aregit,hg,pijul, orfossilโ or you can saynoneand not initialize any version control at all. if you don't specify anything, it defaults togitor the configuration valuecargo-new.vcs, ornoneif you're already inside a VCS repository. it's giving "it depends" but in a helpful way.--registryregistry โ this sets thepublishfield inCargo.tomlto the given registry name, which restricts publishing to only that registry. ๐
registry names are defined in Cargo config files <https://doc.rust-lang.org/cargo/reference/config.html>. if you don't specify one, the default registry defined by the registry.default config key gets used. and if the default registry isn't set and you didn't use --registry? then the publish field just won't be set at all, which means publishing won't be restricted. freedom, basically. ๐ฆ
๐ฅ Display Options ๐ฅ
-v,--verboseโ use verbose output. and yes, you can specify it twice for "very verbose" output, which includes extra output such as dependency warnings and build script output. double it and give it to the next person. may also be specified with theterm.verboseconfig value <https://doc.rust-lang.org/cargo/reference/config.html>.-q,--quietโ do not print cargo log messages. silent mode. stealth mode. ninja mode. ๐ฅท may also be specified with theterm.quietconfig value <https://doc.rust-lang.org/cargo/reference/config.html>.--colorwhen โ control when colored output is used. valid values:auto(default): automatically detect if color support is available on the terminal. it just knows. ๐ฎalways: always display colors. rainbow mode, no apologies. ๐never: never display colors. monochrome moment.
may also be specified with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>.
๐ Common Options ๐
+toolchain โ if Cargo has been installed with rustup, and the first argument tocargobegins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). see the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more info about how toolchain overrides work. it's giving "choose your fighter." โญ--configKEY=VALUE or PATH โ overrides a Cargo configuration value. the argument should be in TOML syntax ofKEY=VALUE, or provided as a path to an extra configuration file. this flag may be specified multiple times. see the command-line overrides section <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more info.-CPATH โ changes the current working directory before executing any specified operations. this affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering.cargo/config.toml, for example. this option must appear before the command name, for examplecargo -C path/to/my-project build. order matters bestie, don't test me on this one. ๐ญ
this option is only available on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z unstable-options flag to enable (see #10098 <https://github.com/rust-lang/cargo/issues/10098>). so like. not for everybody yet. ๐ซถ
-h,--helpโ prints help information. when in doubt, ask for help. no shame. ๐-Zflag โ unstable (nightly-only) flags to Cargo. runcargo -Z helpfor details. the forbidden knowledge section. ๐ง
๐ธ ENVIRONMENT ๐ธ
see the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on environment variables that Cargo reads. there's a whole world of env vars out there, iykyk.
โญ EXIT STATUS โญ
0: Cargo succeeded. ๐ we ate.101: Cargo failed to complete. ๐ not the vibe.
๐ EXAMPLES ๐
- Create a binary Cargo package in the given directory:
cargo new foo
boom. foo. done. periodt. ๐
๐ SEE ALSO ๐
and that's the whole page bestie!! this was CARGO-NEW(1) from the General Commands Manual โ go forth and make packages, you've got this ๐ซถโจ๐
๐ฆ where this page comes from
- ubuntu jammy: cargo-1.85 1.85.1+dfsg0ubuntu2~bpo0-0ubuntu1.22.04.1 ยท Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.85 1.85.1+dfsg0ubuntu2~bpo0-0ubuntu0.24.04.2 ยท Apache-2.0 WITH LLVM exception
- ubuntu questing: cargo-1.85 1.85.1+dfsg0ubuntu2-0ubuntu1
- ubuntu questing: cargo-1.85 1.85.1+dfsg0ubuntu2-0ubuntu1.25.04.1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms