iTranslated by AI
Hello World in Rust
Introduction
In this article, I will walk through the process from installing Rust to outputting Hello World.
Environment
- macOS Ventura
Installing
Run the installation command described on the official website.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
After running the command, you will be asked the following during the process, so select 1.
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
Once the installation is complete, add the path to your environment variables.
$ source "$HOME/.cargo/env"
After the installation is finished, the three tools cargo, rustc, and rustup will be available, so I'll try displaying their versions.
*These are the versions from when I ran the commands on 2023/03/22.
$ cargo --version
cargo 1.68.0 (115f34552 2023-02-26)
$ rustc --version
rustc 1.68.0 (2c8cc3432 2023-03-06)
$ rustup --version
rustup 1.25.2 (17db695f1 2023-02-01)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.68.0 (2c8cc3432 2023-03-06)`
Trying Out Hello World
Create a hello_world.rs file in any location.
Write the following content in the file you created.
fn main () {
println!("Hello World");
}
Once you have written it, let's try compiling it.
$ rustc hello_world.rs
If the compilation is successful, hello_world will be created in the same location as hello_world.rs.
$ ls
$ hello_world hello_world.rs
Finally, execute it.
$ ./hello_world
$ Hello World ← execution result
Discussion