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
-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap