A new Rust project needs more than an empty directory because Cargo creates the manifest, source tree, and target type that the compiler expects before the first build. Starting with Cargo keeps the project layout compatible with the rest of the Rust toolchain from the first run.
cargo new creates a package in a new directory. The binary target is the default, but using --bin keeps the generated layout explicit, and --vcs none leaves version control setup to the surrounding repository or a later git step.
After the package exists, cargo run builds and executes the generated src/main.rs file, while cargo test confirms the default test harness can compile the project. For a library crate, replace --bin with --lib and use cargo test as the first proof instead of a binary run.
Related: How to install Rust on Ubuntu
Related: How to create a Rust workspace with Cargo
$ cargo new hello-rust --bin --vcs none
Creating binary (application) `hello-rust` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Omit --vcs none when Cargo should create a Git repository for the new package.
$ cd hello-rust
$ cat Cargo.toml [package] name = "hello-rust" version = "0.1.0" edition = "2024" [dependencies]
The edition value comes from the current Cargo default. Use --edition only when the project must target an older Rust edition.
$ cat src/main.rs
fn main() {
println!("Hello, world!");
}
$ cargo run
Compiling hello-rust v0.1.0 (/work/hello-rust)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.61s
Running `target/debug/hello-rust`
Hello, world!
Cargo shows the local project path in the compile line; the path will match the directory where the package was created.
$ cargo test
Compiling hello-rust v0.1.0 (/work/hello-rust)
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.39s
Running unittests src/main.rs (target/debug/deps/hello_rust-d6307a738c252336)
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
A new binary package starts with zero tests; ok confirms the generated target compiles under the test profile.
Related: How to run Rust tests with Cargo