CARGO-INIT(1)

πŸ“¦
version 1.99.1 Β· 6 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0

πŸ’– 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 πŸ¦‹
  • --edition edition β€” pick which Rust edition you want. default is 2024. the possible values are: 2015, 2018, 2021, 2024
  • --name name β€” set the package name yourself. if you don't, it defaults to the directory name (which is usually fine, but you do you πŸ’)
  • --vcs vcs β€” initialize a new VCS repository for the given version control system. your options are git, hg, pijul, or fossil β€” or none if you want zero version control, living dangerously fr fr. if you don't specify anything, it defaults to git, or to the configuration value cargo-new.vcs, or none if you're already inside a VCS repository.
  • --registry registry β€” this sets the publish field in Cargo.toml to 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 the term.verbose config value at https://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 the term.quiet config value at https://doc.rust-lang.org/cargo/reference/config.html.
  • --color when β€” 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 to cargo starts with +, it gets interpreted as a rustup toolchain name β€” like +stable or +nightly. see the rustup documentation at https://rust-lang.github.io/rustup/overrides.html for more on how toolchain overrides work. cute lil plus sign, huge power.
  • --config KEY=VALUE or PATH β€” overrides a Cargo configuration value. the argument should be in TOML syntax as KEY=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 at 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 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, like cargo -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-options flag to enable (see #10098 at https://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 πŸ’–
  • -Z flag β€” unstable (nightly-only) flags to Cargo. run cargo -Z help for 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 🧚

  1. 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