EN | DE

Stage 2.4: cargo

cargo is Rust's official package manager. If you've installed Rust with rustup, then cargo is already installed. You can verify that by running cargo --version

To see all available options you have with cargo, simply run: cargo --help

cargo is used for

  • Creating new projects with:
    • cargo new my-project - This will create a new folder my-project with a basic setup.
    • cargo init - this will create a new setup in the current folder.
  • Compile your code:
    • cargo build - creates a new debug build.
    • cargo build --release - creates an optimized build for production.
  • Alternatively you can do compiler checks without compilation with cargo check
  • During development you can also compile and execute it directly with cargo run
  • To get a documentation of your code and all your used dependencies, simly run: cargo doc --open
  • To run tests, just execute cargo test
  • Formatting your code? No problem with cargo fmt
  • and many more

In the next lesson you will learn how to deal with dependencies in Rust using cargo.

Further information:

Rust mascot Ferris