cargo-new
Create a new Cargo package
TLDR
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). Defaults to latest stable edition.--vcs type
Version control system (git, hg, pijul, fossil, none)--registry name
Registry for publishing-v, --verbose
Verbose output-q, --quiet
Suppress output--color when
Coloring: auto, always, never.--offline
Run without accessing the network.
GENERATED STRUCTURE
├── Cargo.toml
├── .gitignore
└── src/
└── main.rs (or lib.rs)
CAVEATS
Use `cargo init` for existing directories. Package names must use only alphanumeric characters, hyphens, or underscores. Cannot be created inside an existing Cargo workspace unless the workspace explicitly excludes the path.
HISTORY
cargo is the package manager and build tool for the Rust programming language, first released with Rust 1.0 in 2015. The new subcommand has been a core part of Cargo since the beginning, streamlining project initialization.
SEE ALSO
cargo(1), cargo-init(1), cargo-build(1)
