# What is Cargo, and what does it do for me?
Source: https://ruststudio.org/community/t/5/what-is-cargo-and-what-does-it-do-for-me
Author: Ruststudio Team (staff) | Published: 2026-12-05 | Updated: 2026-12-05 | Checked with: cargo 1.93.0, Windows 11
Category: Help and questions | Kind: FAQ | Tags: cargo, basics, tooling | Views: 0

## Short answer
Cargo is Rust's build tool and package manager. One command creates a project, downloads and builds its dependencies from crates.io, compiles, runs and tests it. Project settings and dependencies live in Cargo.toml, and Cargo.lock records the exact versions that were built.

## Answer
## Answer
Cargo is installed with Rust (through rustup) and is the command you use for almost everything: creating projects, adding libraries (called crates), building, running, testing and publishing. You rarely call the compiler, `rustc`, by hand.

A project is a folder with a `Cargo.toml` file (its description and dependencies) and a `src` folder. Cargo also writes `Cargo.lock`, which pins the exact version of every dependency, and a `target` folder that holds everything it builds.

## How to do it
1. Create a project. This also starts a Git repository in the folder unless it is already inside one.

   ```sh
   cargo new hello
   ```

   This is the `Cargo.toml` it writes with cargo 1.93.0:

   ```toml title=Cargo.toml
   [package]
   name = "hello"
   version = "0.1.0"
   edition = "2024"

   [dependencies]
   ```

2. Build and run it. The first command compiles in the fast-to-build debug profile; `target/debug` holds the result.

   ```sh
   cargo run
   ```

   ```text
   Hello, world!
   ```

3. Run the tests (there are none yet, so the result is empty but passes).

   ```sh
   cargo test
   ```

4. Add a dependency. The command edits `Cargo.toml` for you and picks the newest compatible version.

   ```sh
   cargo add serde_json
   ```

5. Check the code without producing a program. This is much faster than a build and reports the same errors.

   ```sh
   cargo check
   ```

6. Build an optimised program for release. It is placed in `target/release`.

   ```sh
   cargo build --release
   ```

| Command | What it does |
|---|---|
| `cargo new`, `cargo init` | Create a project in a new or existing folder |
| `cargo check` | Type-check without producing a program |
| `cargo build`, `cargo build --release` | Compile (debug, or optimised) |
| `cargo run` | Build, then run |
| `cargo test` | Build and run the tests |
| `cargo add`, `cargo remove` | Edit the dependency list |
| `cargo tree` | Show the dependency graph |
| `cargo update` | Move `Cargo.lock` to newer versions |
| `cargo clean` | Delete the `target` folder |

## Common mistakes
- Committing the `target` folder to Git. It is large and rebuildable; the `.gitignore` that `cargo new` writes already excludes it.
- Forgetting `--release` when measuring speed. Debug builds are often many times slower.
- Never cleaning old `target` folders. Each project keeps its own, and they grow large over time.

## In Ruststudio
Ruststudio runs these commands for you from its menus and shows their output, and its Cargo Cleaner finds the `target` folders and cargo caches on your disk, with their size and age, and deletes only what you tick. See [the Cargo Cleaner page](/cargo-cleaner).

## Related questions
### What is the difference between Cargo.toml and Cargo.lock?
`Cargo.toml` is what you write: the dependencies you want, with version ranges. `Cargo.lock` is what Cargo writes: the exact versions it chose. Commit `Cargo.lock` for programs so that every build uses the same versions.

### What is a crate?
A crate is one unit of Rust code that is compiled together: a library or a program. Libraries from crates.io are crates, and so is your own program.

## Sources
- The Cargo Book: https://doc.rust-lang.org/cargo/
- Cargo commands: https://doc.rust-lang.org/cargo/commands/index.html
