Getting Started with Rust
So this is it, you’ve decided to pack your things, leave your old programming language behind and start learning Rust.
But where do you start?
Well, we all have to start from measly humble beginnings and the first thing you’ll need to do is grab a cup of coffee, sit down, and install the Rust programming language on your machine.
Installing Rust
The easiest way to install Rust is to navigate to https://www.rust-lang.org/tools/install
and follow the instructions there - at the time of writing this, it was a fairly straightforward 1-liner that you could run in your terminal.
For the security conscious among you, don’t worry, I’ve not noticed any money being drained from my bank account just yet after running this command, but there is still time!
Keeping your Rust Installation Up to Date
Running the link above should install the rustup
toolchain on your machine which will allow you to keep your Rust installation up to date.
It feels like the language is moving at breakneck speed with the constant updates and patches being released, so it’s really nice that they have a super-straightforward way of keeping your installation up to date.
$ rustup update
$ rustc --version
rustc 1.80.0 (051478957 2024-07-21)
For those of you that break on your Rust learning journey, you can uninstall Rust at any point by running the following command:
$ rustup self uninstall
Creating a New Project
Parfait! You’ve got Rust installed on your machine and you’re ready to start creating your first project.
Rust comes with a super-handy tool called cargo
which is effectively the Rust package manager and build tool. We can leverage this tool for nefarious project-bootstrapping means by running the following command:
cargo new hello_world
This will create a new directory called hello_world
and scaffold out a new Rust project for you.
Building and Running your Project
Now that you’ve got your project scaffolded out, you can navigate into the directory and run the following command to build and run your project:
cd hello_world
cargo run
This will compile your Rust project and run it, outputting the following to your terminal:
Compiling hello_world v0.1.0 (/Users/elliotforbes/hello_world)
Finished dev [unoptimized + debuginfo] target(s) in 0.23s
Running `target/debug/hello_world`
Hello, world!
And that’s it!
You’ve successfully created and run your first Rust project! This is just the beginning of your Rust journey and I hope you enjoy the ride!