Hello, Rust: Your First Program
Install Rust with rustup, create a project with Cargo, and run your first program that prints Hello, World.
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 | shbashAfter it finishes, reload your shell and verify:
rustc --version
cargo --versionbashYour first program#
Create a new project with Cargo, Rust’s build system and package manager:
cargo new hello_rust
cd hello_rustbashCargo generates src/main.rs with a ready-made program:
fn main() {
println!("Hello, world!");
}rustRun it#
cargo runbashOutput:
Hello, world!textWhat 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 aCargo.tomlmanifest.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 mistakesbashRun 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.