CARGO-INIT(1)
π CARGO-INIT(1) π
okay bestie, welcome to cargo-init β it's a manual page from the General Commands Manual, and it's here to teach you how to spin up a brand new Cargo package in a directory that already exists. no cap. let's get into it π¦
β¨ NAME β¨
cargo-init β create a new Cargo package in an existing directory πΈ
π SYNOPSIS π
cargo init [options] [path]
π§ DESCRIPTION π§
so basically, this command creates a new Cargo manifest in the current directory. it's giving main character energy β¨ and if you hand it a path as an argument, it'll go create the thing over in that directory instead. slay.
if there are typically-named Rust source files already chillin' in the directory, those get used. and if there aren't? no worries bestie, a sample src/main.rs file gets created β or src/lib.rs if you pass --lib. π
and if the directory isn't already inside a VCS repository, then a whole new repository gets created (peep --vcs down below π).
also! go look at cargo-new(1) for a similar command that makes a new package in a new directory instead. different vibe, same family π«Ά
π OPTIONS π
π₯ Init Options
--binβ create a package with a binary target (src/main.rs). this is the default behavior, iykyk. π--libβ create a package with a library target (src/lib.rs). π--edition editionβ specify the Rust edition to use. default is2024. possible values:2015,2018,2021,2024. β--name nameβ set the package name. defaults to the directory name. (so if your folder's calledmy-cool-thing, congrats, that's your package name π)--vcs vcsβ initialize a new VCS repository for the given version control system (git,hg,pijul, orfossil) β or don't initialize any version control at all (none). if not specified, it defaults togit, or the configuration valuecargo-new.vcs, ornoneif you're already inside a VCS repository. π--registry registryβ this sets thepublishfield inCargo.tomlto the given registry name, which will restrict publishing only to that registry.
registry names are defined in Cargo config files: https://doc.rust-lang.org/cargo/reference/config.html. if not specified, the default registry defined by the registry.default config key is used. if the default registry is not set and --registry is not used, the publish field will not be set, which means that publishing will not be restricted. π
π Display Options
-v,--verboseβ use verbose output. may be specified twice for "very verbose" output, which includes extra output such as dependency warnings and build script output. 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. may also be specified with theterm.quietconfig 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. πalways: always display colors. πnever: never display colors. π
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+stableor+nightly). see the rustup documentation athttps://rust-lang.github.io/rustup/overrides.htmlfor more information about how toolchain overrides work. π¦--config KEY=VALUEorPATHβ 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 athttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor more information. π§-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 examplecargo -C path/to/my-project build.
β οΈ 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-optionsflag to enable (see #10098 athttps://github.com/rust-lang/cargo/issues/10098). so like, not for the faint of heart fr fr.
-h,--helpβ prints help information. π-Z flagβ unstable (nightly-only) flags to Cargo. runcargo -Z helpfor details. π
πΈ ENVIRONMENT πΈ
see the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads. yes bestie, Cargo is nosy like that π
π EXIT STATUS π
0: Cargo succeeded. π101: Cargo failed to complete. π
π¦ EXAMPLES π¦
- Create a binary Cargo package in the current directory:
cargo init
π SEE ALSO π
cargo(1), cargo-new(1) β go read those too, they're iconic π
and that's the whole page, bestie!! this was CARGO-INIT(1) from the General Commands Manual, signed off with love. now go cargo init something iconic and make it your whole personality β¨π
π«Ά
π¦ 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