Rust: Write and Run Hello World! Program Example

  1. Open a Text Editor (Notepad/Notepad++/TextEdit or Sublime based on your OS).
  2. Write the following to it.
    fn main() {
        println!("Hello World!");
    }
  3. Save the file as main.rs
Writing Hello World Rust Lang Program in Mac TextEdit

Steps to Run the "Hello World!" Rust Program

  1. Open Terminal (if on Mac/Linux/Ubuntu) or Command Prompt (if on Windows)
  2. Move to the location where you have created the main.rs file.
  3. Run the command: rustc main.rs to compile our "Hello World!" program.
    rustc main.rs
  4. Finally, we are good to run our program,
    ./main
  5. Output:

    Hello World!

Rust - Running Hello World Program on Mac

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!