CARGO-INIT(1)
π CARGO-INIT(1) π
okay so this is the General Commands Manual page for cargo-init, bestie π β the one and only guide to making a brand new Cargo package pop off inside a directory you already have. Let's get into it π
β¨ NAME β¨
cargo-init β Create a new Cargo package in an existing directory π¦
β¨ SYNOPSIS β¨
cargo init [options] [path]
β¨ DESCRIPTION β¨
so here's the vibe: this command creates a fresh new Cargo manifest in whatever directory you're standing in right now. Wanna do it somewhere else? Just hand it a path as an argument and it'll set up shop in that directory instead π«Ά
If there are already Rust source files in there with the typical names, it will literally just use those β no notes, they ate π
. If there aren't any, then it makes you a sample src/main.rs file, or src/lib.rs if you pass --lib.
If the directory isn't already inside a VCS repository, then a whole new repository gets created (peep --vcs below π).
also!! check out cargo-new(1) if you want the sibling command β that one creates a new package in a new directory. Different energy, same family πΈ
β¨ OPTIONS β¨
π« Init Options
--binβ Create a package with a binary target (src/main.rs). This is the default behavior, so if you do nothing at all, this is what you get π--libβ Create a package with a library target (src/lib.rs). Library girlies rise π§--editionedition β Specify the Rust edition to use. Default is2021. Possible values:2015,2018,2021,2024β--namename β Set the package name. Defaults to the directory name.--vcsvcs β Initialize a new VCS repository for the given version control system (git,hg,pijul, orfossil) or do not initialize any version control at all (none). If not specified, defaults togitor the configuration valuecargo-new.vcs, ornoneif already inside a VCS repository. Choose wisely bestie π--registryregistry β 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 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 valuehttps://doc.rust-lang.org/cargo/reference/config.html.-q,--quietβ Do not print cargo log messages. May also be specified with theterm.quietconfig valuehttps://doc.rust-lang.org/cargo/reference/config.html. Shhh π€«--colorwhen β 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 documentationhttps://rust-lang.github.io/rustup/overrides.htmlfor more information about how toolchain overrides work.--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 sectionhttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor more information.-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.
heads up!! This option is only available on the nightly channelhttps://doc.rust-lang.org/book/appendix-07-nightly-rust.htmland requires the-Z unstable-optionsflag to enable (see #10098https://github.com/rust-lang/cargo/issues/10098).
-h,--helpβ Prints help information. The classic π«Ά-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 details on environment variables that Cargo reads π±
β¨ EXIT STATUS β¨
0: Cargo succeeded. π slay101: Cargo failed to complete. π
β¨ EXAMPLES β¨
- Create a binary Cargo package in the current directory:
cargo init
β¨ SEE ALSO β¨
cargo(1), cargo-new(1) π
and that's the whole page, bestie!! the footer just says CARGO-INIT(1) again (iconic of it honestly) β no version number, no date, just the name of this page from the Cargo manual's General Commands Manual section, chilling at the bottom. periodt π
β¨π
π¦ where this page comes from
- ubuntu jammy: cargo-1.81 1.81.0+dfsg0ubuntu0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.81 1.81.0+dfsg0ubuntu1-0ubuntu0.24.04.1 Β· 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