Originally published on php2rust.dev — part of the PHP to Rust course. View this lesson on the original site.

To compile and run your Rust program, open a terminal or command prompt, navigate to the directory containing your hello.rs file, and run:

rustc hello.rs

This compiles your source code into an executable binary named hello (or hello.exe on Windows). Rust compiles in debug mode by default, which adds debugging information and uses fewer optimizations to keep builds fast during development.

To run the executable:

./hello

On Windows, use hello.exe instead.

You should see Hello, Rust! printed to the console, confirming that your Rust program ran successfully.

What's next

Next: Verifying Cargo installation.

From PHP to Rust — Getting Started with Rust