cargo-new
Create a new Cargo package
TLDR
Create new binary project
SYNOPSIS
cargo new [options] path
DESCRIPTION
cargo new creates a new Cargo package in a new directory. It generates a Cargo.toml manifest file, a src/ directory with either a "Hello, World!" binary (`main.rs`) or a library stub (`lib.rs`), and initializes a git repository by default.
The generated Cargo.toml includes the package name, version, and Rust edition. The command respects Cargo configuration for default settings such as author name and email, which are read from git config or environment variables. Custom templates are not supported; use `cargo-generate` for template-based project creation.
PARAMETERS
--bin
Create binary with src/main.rs (default)--lib
Create library with src/lib.rs--name name
Package name (defaults to directory name)--edition year
Rust edition (2015, 2018, 2021, 2024)--vcs type
Version control system (git, hg, pijul, fossil, none)--registry name
Registry for publishing-v, --verbose
Verbose output-q, --quiet
Suppress output
GENERATED STRUCTURE
├── Cargo.toml
├── .gitignore
└── src/
└── main.rs (or lib.rs)
CAVEATS
Use cargo init for existing directories. Default edition is 2024 in recent Rust versions.
SEE ALSO
cargo(1), cargo-init(1), cargo-build(1)
