- Open a Text Editor (Notepad/Notepad++/TextEdit or Sublime based on your OS).
- Write the following to it.
fn main() { println!("Hello World!"); }
- Save the file as main.rs
![Writing Hello World Rust Lang Program in Mac TextEdit Writing Hello World Rust Lang Program in Mac TextEdit](https://code2care.org/rust/rust-lang-write-and-run-hello-world-program-example/images/Writing Hello World Rust Lang Program in Mac TextEdit.jpg)
Steps to Run the "Hello World!" Rust Program
- Open Terminal (if on Mac/Linux/Ubuntu) or Command Prompt (if on Windows)
- Move to the location where you have created the main.rs file.
- Run the command: rustc main.rs to compile our "Hello World!" program.
rustc main.rs
- Finally, we are good to run our program,
./main
Output:
![Rust - Running Hello World Program on Mac Rust - Running Hello World Program on Mac](https://code2care.org/rust/rust-lang-write-and-run-hello-world-program-example/images/Rust - Running Hello World Program on Mac.jpg)
Facing issues? Have Questions? Post them here! I am happy to answer!
Author Info:
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
More Posts related to Rust,
- Rust: Cargo Init vs Cargo New Command
- Rust: Write and Run Hello World! Program Example
- How to Split a String using Rust Language
- How to Sort a Vector in Rust with Examples
- Fix: error: could not find `Cargo.toml` in Users or any parent directory
- How to uninstall Rust Language from Mac/Linux/Ubuntu
- How to update Cargo (Rust Lang)
- Fix: rust-analyzer failed to discover workspace [Visual Studio Code]
- How to install Rust using rustup on macOS/Linux/Ubuntu
- Cargo Watch: To Recompile Rust Project Automatically
- Difference between rustc and cargo build commands
- How to Split a String by Space in Rust
- How to know Rust is Installed on Mac?
- Rust: zsh: no such file or directory: ./main
- How to update Rust on Mac/Linux
- List of Rust Cargo Commands
- How to find version of Cargo in Rust
- Fix: error: mismatched closing delimiter } [Rust]
More Posts:
- How to migrate SharePoint Designer 2010 workflow to Power Automate FLOW (Microsoft Office 365) - SharePoint
- Step-by-Step: How to install Flutter in Android Studio - Android-Studio
- Most Essencial AWS CLI 2 S3 ls Command Options - AWS
- Java JDBC Connection with PostgreSQL Driver Example - Java
- How to make jsfiddle bootstrap ready - CSS
- How to Open Calculator using Mac Terminal - MacOS
- Python Comments Multiple Lines - Python
- How to get weather details in Command Prompt, macOS or Linux Terminal - HowTos