LinuxCommandLibrary

cargo-init

Create a new Rust package in an existing directory

TLDR

Initialize in current directory

$ cargo init
copy
Initialize binary project
$ cargo init --bin
copy
Initialize library
$ cargo init --lib
copy
Initialize without git
$ cargo init --vcs none
copy
Initialize with specific name
$ cargo init --name [myproject]
copy
Initialize with specific edition
$ cargo init --edition [2021]
copy

SYNOPSIS

cargo init [options] [path]

DESCRIPTION

cargo init creates a new Cargo package in an existing directory. Generates Cargo.toml and src/ with either main.rs (binary) or lib.rs (library). Unlike cargo new, does not create a new directory.

PARAMETERS

--bin

Create binary target with src/main.rs (default)
--lib
Create library target with src/lib.rs
--name name
Set package name (defaults to directory name)
--edition year
Rust edition (2015, 2018, 2021, 2024)
--vcs type
Initialize version control (git, hg, pijul, fossil, none)
--registry name
Registry for publishing
-v, --verbose
Verbose output
-q, --quiet
Suppress output

GENERATED FILES

$ .
├── Cargo.toml
├── .gitignore (if using git)
└── src
    └── main.rs (or lib.rs)
copy

CAVEATS

Default edition is 2024 in recent Rust versions. Initializes git repository by default if not already in one.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community