CARGO-INIT(1)
π CARGO-INIT β the glow-up command β¨
okay bestie, listen. this is cargo-init, straight outta the General Commands Manual, and it's literally the "make me a whole Rust package, right here, right now" button. no cap.
πΈ SYNOPSIS πΈ
cargo init [options] [path]
π DESCRIPTION π
so the whole vibe is: this command creates a brand-new Cargo manifest in the directory you're standing in. you can also hand it a path as an argument and it'll do the thing in that directory instead. iconic behaviour, honestly.
if there are already Rust source files sitting in there with the typical names, it's gonna use those. no drama. but if there aren't any, it'll spin up a lil sample src/main.rs for you β or src/lib.rs instead if you passed --lib. slay.
also, if the directory isn't already chilling inside a VCS repository, a new repository gets created. (peep --vcs down below, iykyk π)
pro tip from me to you: check out cargo-new(1) if you want the sibling command β that one makes a new package in a new directory. different energy, same family.
β¨ OPTIONS β¨
π Init Options
--binβ makes a package with a binary target (src/main.rs). this is the default, so it's giving "I didn't even have to try" π--libβ makes a package with a library target (src/lib.rs). library girlies rise π¦--editionedition β pick which Rust edition you want. default is2024. the possible values are:2015,2018,2021,2024--namename β set the package name yourself. if you don't, it defaults to the directory name (which is usually fine, but you do you π)--vcsvcs β initialize a new VCS repository for the given version control system. your options aregit,hg,pijul, orfossilβ ornoneif you want zero version control, living dangerously fr fr. if you don't specify anything, it defaults togit, or to the configuration valuecargo-new.vcs, ornoneif you're already inside a VCS repository.--registryregistry β this sets thepublishfield inCargo.tomlto the registry name you give it, which restricts publishing so it can only go to that registry. gatekeeping, but make it config.
registry names are defined in the Cargo config files at 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 doesn't get set at all, which means publishing isn't restricted. free-for-all, periodt.
π Display Options
-v,--verboseβ verbose output, bestie. you can even specify it twice for "very verbose" output, which throws in extra stuff like dependency warnings and build script output. you can also set this with theterm.verboseconfig value athttps://doc.rust-lang.org/cargo/reference/config.html. say it with me: more words, more power.-q,--quietβ do NOT print cargo log messages. silence is golden π. can also be set with theterm.quietconfig value athttps://doc.rust-lang.org/cargo/reference/config.html.--colorwhen β controls when colored output shows up. valid values are:auto(default): automatically detects if the terminal supports color. it's checking the vibe πalways: always display colors. rainbow mode, no apologies πnever: never display colors. minimalism era.
can also be set with the term.color config value at https://doc.rust-lang.org/cargo/reference/config.html.
π Common Options
+toolchainβ if Cargo got installed with rustup, and the first argument tocargostarts with+, it gets interpreted as a rustup toolchain name β like+stableor+nightly. see the rustup documentation athttps://rust-lang.github.io/rustup/overrides.htmlfor more on how toolchain overrides work. cute lil plus sign, huge power.--config KEY=VALUEorPATHβ overrides a Cargo configuration value. the argument should be in TOML syntax asKEY=VALUE, or you can hand it a path to an extra configuration file instead. this flag can be specified multiple times. see the command-line overrides section athttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor more info.-C PATHβ 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 which directories get searched for discovering.cargo/config.toml, for example. this option has to come 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). so, y'know, not for the faint of heart π«Ά
-h,--helpβ prints help information. when in doubt, ask for help, that's self-care π-Zflag β unstable (nightly-only) flags to Cargo. runcargo -Z helpfor details. very "I know a guy" energy.
π± ENVIRONMENT π±
see the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for all the details on environment variables that Cargo reads. it's a whole lore drop, ngl.
β EXIT STATUS β
0: Cargo succeeded. we ate and left no crumbs π101: Cargo failed to complete. π it's not you, it's the build.
π§ EXAMPLES π§
- Create a binary Cargo package in the current directory:
cargo init
π₯ SEE ALSO π₯
and that's the whole page, bestie π this was CARGO-INIT(1) from the General Commands Manual β shoutout to the source and version for making it all possible, and to the date for timestamping our little journey. go forth and cargo init, you absolute main character πβ¨
π¦ where this page comes from
- ubuntu jammy: cargo-1.89 1.89.0+dfsg~24.04-0ubuntu0.22.04.2 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.89 1.89.0+dfsg~24.04-0ubuntu0.24.04.2 Β· Apache-2.0 WITH LLVM exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms