# Cargo - Rust Package Manager
## Basic Commands
```bash
cargo build # Build the project
cargo run # Build and run the project
cargo check # Check for errors without building
cargo init # Initialize in existing directory
cargo new <name> # Create new project
cargo build --release # Build with optimizations
cargo doc --open # Build and open documentation
cargo update # Update dependencies in Cargo.lock
```
## Cargo.lock - Reproducible Builds
### Prevents automatic updates
```bash
cargo update
```
This command will update dependencies in the `Cargo.lock` file to the latest version. If the `Cargo.lock` file does not exist, it will be created with the latest available versions.
> When you build a project for the first time, Cargo figures out all the versions of the dependencies that fit the criteria and then writes them to the `Cargo.lock` file. When you build your project in the future, Cargo will see that the `Cargo.lock` file exists and will use the versions specified there rather than doing all the work of figuring out versions again. This lets you have a reproducible build automatically. In other words, your project will remain at a specific version until you explicitly upgrade, thanks to the `Cargo.lock` file.
>
> The `Cargo.lock` file is important for reproducible builds and should be checked into source control with the rest of the code in your project.
>
> — [The Rust Programming Language, Ch. 2](https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html)