- Run in the terminal:
curl https://sh.rustup.rs -sSf | sh
- Reboot
- Confirm installation:
cargo --version
- If
command not found: cargo
: then: read this
If you want to create (compile) your code manually, you will use rustc
.
Example:
Create a file main.rs
: touch main.rs
Write a hello world
-example:
fn main() {
println!("Hello, World!");
}
Create the file (compile): rustc main.rs
Run the created file: ./main
Workflow:
- Write code in
.rs
- Compile file with:
rustc [code-file]
- Run compiled file:
./[compiled-file]
Most of the time you will use cargo
, the Rust package manager.
Create a new rust project (like npm init
): cargo new [name]
Compile & run project: cargo run
fn main() {
println!("Hello, World!");
}
There is a function named main
.
It has no parameters, ()
.
The main function is special, because it always runs first.