The first part of getting hands-on experience with Rust is installing Rust. In order to install Rust, we need a Rust installer.
Rustup is a version management tool and also an installer that helps in installing Rust in your local machine.
If you’re running Linux, macOS, or another Unix-like OS, then we simply need to run the following command in the terminal −
curl --proto ‘=https’ --tlsv1.2 -sSf https://sh.rustup.rs | sh
The above command will install Rust on your local machine.
If you are on Windows, then you can download the .exe file from this link rustup-init.exe
Though Rust is updated frequently, but you can always make sure that it is up-to-date by running the following command −
We can test whether we’ve correctly installed Rust and Cargo by running the following command in any terminal of our choice −
Let’s make use of Cargo to create a new Rust project. In your terminal, run the following command −
cargo new hello-tutorialspoint
The above command will generate a new directory called hello-tutorialspoint with the following files −
hello-tutorialspoint |-- Cargo.toml |-- src |-- main.rs
It’s always a tradition that we write a “Hello, world!” program whenever we are learning a new programming language. In Rust, Cargo provides us with the same, we just need to run the following command in our terminal −
The above command will generate a “Hello, world!” project. In order to run the project, we need to move into the new directory that we made and run the following command in the terminal −
After running this command, you’ll have something similar to this −
Compiling hello-tutorialspoint v0.1.0 (/Users/immukul/hello-tutorialspoint) Finished dev [unoptimized + debuginfo] target(s) in 2.39s Running `target/debug/hello-tutorialspoint` Hello, world!