blog.dopana

Back

This is the first post in a series about basic Rust. Rust is a systems language focused on memory safety, speed, and fearless concurrency — and its compiler is famous for catching bugs before they run.

Install Rust with rustup#

The official way to install Rust is rustup, which manages toolchains:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
bash

After it finishes, reload your shell and verify:

rustc --version
cargo --version
bash

Your first program#

Create a new project with Cargo, Rust’s build system and package manager:

cargo new hello_rust
cd hello_rust
bash

Cargo generates src/main.rs with a ready-made program:

src/main.rs
fn main() {
    println!("Hello, world!");
}
rust

Run it#

cargo run
bash

Output:

Hello, world!
text

What each part does#

  • fn main() — the entry point where every Rust program starts.
  • println! — a macro (note the !) that prints a line of text to the console.
  • cargo new — creates the project with a Cargo.toml manifest.
  • cargo run — compiles and runs the program.

Try cargo build to only compile, and cargo check to check for errors quickly without producing a binary.

Formatting and linting#

Rust ships with two tools:

cargo fmt # formats your code
cargo clippy # catches common mistakes
bash

Run them on every project. The compiler itself is also a great teacher — read its error messages carefully.

Conclusion#

You installed Rust, created a project with Cargo, and ran your first program. Next in this series: variables and data types.

References#