CARGO-NEW(1)

๐Ÿ“ฆ version 1.85.1, in ubuntu jammy, ubuntu noble, ubuntu questing

๐Ÿ’– 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 ๐Ÿ“š
  • --edition edition โ€” specify which Rust edition to use. default is 2024. possible values: 2015, 2018, 2021, 2024. pick your era bestie, there are literally four of them.
  • --name name โ€” set the package name. if you don't, it defaults to the directory name. no thoughts, just folder name. ๐Ÿ™ˆ
  • --vcs vcs โ€” initialize a new VCS repository for the given version control system. your options are git, hg, pijul, or fossil โ€” or you can say none and not initialize any version control at all. if you don't specify anything, it defaults to git or the configuration value cargo-new.vcs, or none if you're already inside a VCS repository. it's giving "it depends" but in a helpful way.
  • --registry registry โ€” this sets the publish field in Cargo.toml to 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 the term.verbose config 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 the term.quiet config value <https://doc.rust-lang.org/cargo/reference/config.html>.
  • --color when โ€” 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 to cargo begins with +, it will be interpreted as a rustup toolchain name (such as +stable or +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." โญ
  • --config KEY=VALUE or PATH โ€” overrides a Cargo configuration value. the argument should be in TOML syntax of KEY=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.
  • -C PATH โ€” 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 example cargo -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. ๐Ÿ’œ
  • -Z flag โ€” unstable (nightly-only) flags to Cargo. run cargo -Z help for 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 ๐Ÿ“

  1. Create a binary Cargo package in the given directory:
cargo new foo

boom. foo. done. periodt. ๐Ÿ’…


๐Ÿ’œ SEE ALSO ๐Ÿ’œ

cargo(1), cargo-init(1)


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