CARGO-NEW(1)
π CARGO-NEW β Create a New Cargo Package π
okay bestie, welcome to cargo-new(1), straight out of the General Commands Manual π this is the one that spins up a whole brand-new Cargo package for you, like, from absolutely nothing. iconic behavior fr fr.
β¨ SYNOPSIS β¨
cargo new [options] path
π¦ DESCRIPTION π¦
so the way this works: this command creates a shiny new Cargo package in the directory you point it at. it's giving starter pack β you get a lil template with a Cargo.toml manifest, a sample source file, and a VCS ignore file. π«Ά
and if that directory isn't already chillin' inside a VCS repository? boom, a new repository gets created for you (peep --vcs down below for the deets).
π‘ if you wanna create a new manifest inside a directory that already exists, that's a whole different vibe β go check cargo-init(1), it's the sibling command bestie.
π OPTIONS π
πΈ New Options πΈ
--binβ makes a package with a binary target (src/main.rs). and ngl, this is the default behavior, so if you do nothing you already get this one. slay.--libβ makes a package with a library target (src/lib.rs).--editionedition β pick which Rust edition you want. default is2021. the possible values are:2015,2018,2021,2024. choose your fighter π--namename β sets the package name. if you don't say anything, it defaults to the directory name.--vcsvcs β initializes a new VCS repository for whichever version control system you name (git,hg,pijul, orfossil), or initializes no version control at all (none). if you don't specify it, it defaults togitor the config valuecargo-new.vcs, ornoneif you're already inside a VCS repository. iykyk.--registryregistry β this sets thepublishfield inCargo.tomlto whatever registry name you give it, 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 theregistry.defaultconfig key gets used. and if the default registry isn't set and you didn't pass--registry, then thepublishfield just doesn't get set at all, which means publishing won't be restricted. π
π Display Options π
-v,--verboseβ use verbose output. you can specify it twice for "very verbose" output, which includes extra output like dependency warnings and build script output. can also be set with theterm.verboseconfig value (https://doc.rust-lang.org/cargo/reference/config.html). talkative queen β¨-q,--quietβ do not print cargo log messages. can also be set with theterm.quietconfig value (https://doc.rust-lang.org/cargo/reference/config.html). silence, but make it chic π€«--colorwhen β controls when colored output is used. valid values:auto(default): automatically detect if color support is available on the terminal.always: always display colors. πnever: never display colors.
can also be set with the term.color config value (https://doc.rust-lang.org/cargo/reference/config.html).
π Common Options π
+toolchainβ if Cargo was installed with rustup, and the first argument to cargo starts with+, it gets interpreted as a rustup toolchain name (like+stableor+nightly). see the rustup documentation (https://rust-lang.github.io/rustup/overrides.html) for more info on how toolchain overrides work.--configKEY=VALUE or PATH β overrides a Cargo configuration value. the argument should be in TOML syntax ofKEY=VALUE, or given as a path to an extra configuration file. this flag can be specified multiple times. see the command-line overrides section (https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides) for more.-CPATH β changes the current working directory before executing any specified operations. this affects stuff like where cargo looks by default for the project manifest (Cargo.toml), and also the directories it searches when discovering.cargo/config.toml, for example. this option must appear before the command name, likecargo -C path/to/my-project build.
β οΈ heads up bestie, this option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and it requires the-Z unstable-optionsflag to enable (see #10098 athttps://github.com/rust-lang/cargo/issues/10098). no cap.
-h,--helpβ prints help information.-Zflag β unstable (nightly-only) flags to Cargo. runcargo -Z helpfor details. π₯
π ENVIRONMENT π
see the reference (https://doc.rust-lang.org/cargo/reference/environment-variables.html) for all the details on environment variables that Cargo reads. the lore is all there, go read it π§
β EXIT STATUS β
0: Cargo succeeded. π101: Cargo failed to complete. π
πΈ EXAMPLES πΈ
- create a binary Cargo package in the given directory:
cargo new foo
π«Ά SEE ALSO π«Ά
and that's the whole page, bestie π
this was CARGO-NEW(1) from the General Commands Manual, dated CARGO-NEW(1) β okay so the footer literally just says the page name again, which is very main character of it. go forth and cargo new something iconic πβ¨
π¦ where this page comes from
- ubuntu jammy: cargo-1.80 1.80.1+dfsg0ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.80 1.80.1+dfsg0ubuntu1-0ubuntu0.24.04.01 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms