Chapter 1. Getting Started

👋 Hey there! Welcome to the first chapter of my our Rust adventure. In this section, we’re going to kick things off by getting our hands dirty with the basics.

First up, we'll tackle the installation of Rust on a Linux machine. Rust will, of course, work on Mac or Windows, however, I recommend you use some sort of 'nix environment. It's all straightforward, I promise!

Next, we’ll dive straight into the fun part: writing our very first Rust program. Expect trials, tribulations and maybe a couple of head-scratches, but that's all part of the learning journey, right?

Finally, we’ll meet Cargo, Rust's trusty package manager. It's like a Swiss Army knife for Rust packaging and you’ll wonder how you ever lived without it, asumming you've used other languages.

So,

  • ☕️ grab a coffee,
  • 🛋️ get comfy, and
  • ⌨️ let's get going!
Image for Rust With Jason

"Hackerman. He's the most powerful hacker of all time." – Kung Fury

Installing rustup on Linux

To get started simply plop this command into your terminal. It should work for most linux-like environments. If you get an error, try removing the tls specifier - sometimes system vendors build curl on their own TLS backends rather than rely on OpenSSL.

curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh

If you're on a mac, you need to drop the --tlsv1.3 flag; Apple uses SecureTransport for their TLS stack, rather than OpenSSL.

What's going on here

This command is used to download and install Rust via curl, a command-line tool for transferring data with URLs. It fetches a script and executes it immediately with sh, the Unix shell - this makes things work across various shells, like Bash, Zsh and Fish. If you don't know what those are, that's ok!

Let's break down this command:

  1. curl: The command itself, a tool for transferring data from or to a server, using the https protocol.

  2. --proto 'https': This option tells curl to use only the HTTPS protocol. It restricts curl from attempting to use any other protocol that might normally be attempted in other circumstances.

  3. --tlsv1.3: Specifies that curl should use TLSv1.3 as the cryptographic protocol for secure communication.

TLS (Transport Layer Security) v1.3 is the latest version that provides security improvements over previous versions.

  1. https://sh.rustup.rs: This is the URL from which curl will fetch data. In this case, it's a script provided by the Rust language maintainers to install rustup, the Rust toolchain installer.

  2. -sSf: These are options combined together and passed to curl:

    • -s or --silent: Silent mode. Don't show progress meter or error messages. Makes Curl mute.
    • -S or --show-error: When used with -s, it makes curl show an error message if it fails.
    • -f or --fail: Tells curl to fail silently on server errors (when HTTP servers return a 4xx or 5xx error), preventing scripts or other erroneous data from being executed or processed if the requested URL points to an error page.
  3. | sh: This part is known as a pipe (|). It takes the output of the preceding command (in this case, the script downloaded by curl) and passes it as input to the sh command, which is the command interpreter (or shell) that executes the script.

The overall command fetches the rustup installation script securely using HTTPS and TLSv1.3, and if successful, passes the script directly to the shell for execution. The use of -sSf ensures that the operation proceeds quietly but will show an error if something goes wrong, helping to maintain cleanliness in the output and keep the operation secure.

For more, see the Rust installation docs.

Our first program

Let's create the classic "Hello, world!" program.

The origin of "Hello, World!" can be traced back to the seminal book The C Programming Language by Brian Kernighan and Dennis Ritchie, published in 1978. Often referred to simply as "K&R," this book was instrumental in popularizing the C programming language and served as its de facto standard for years.

Assuming you're in a directory in which you're tracking your Rust learning, mkdir hello_world && cd hello_world to create a directory hello_world and move into it immediately after creation. If this seems overly pedantic, don't worry - we'll reduce detail when doing common things like changing directories in subsequent chapters.

Now create a file main.rs inside of this directory. From now on, we'll use vIM since it's the editor I use. If you use Emacs you can stop reading this book now and request a refund.

vim main.rs

Now inside that file, type the following:

fn main() {
    println!("Hello, world!");
}

Format it:

rustfmt main.rs

And compile then run it:

rustc main.rs && ./main

You should see Hello, world! printed in your terminal. Read more about what's happening under the hood in the Rust docs. Congratulations - you've written and executed your first program!

Cargo FTW

Most Rust developers (Rustaceans) use the language's built-in package manager and build system called Cargo to build "real" programs within Rust. What we did above was using the rust compiler directly, which is a barebones approach that is missing important things like dependency resolution.

So let's move from what we were working on to try out cargo, making the directory hello_cargo in the process: cd ../ && cargo new hello_cargo && cd hello_cargo.

Now open the Cargo.toml file via vim Cargo.toml. You'll see something like:

[package]
name = "hello_cargo"
version = "0.1.0"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

As of January 2026 "four Rust editions are available: Rust 2015, Rust 2018, Rust 2021 and Rust 2024." - read the docs.

The [dependencies] section heading is where you'll add dependencies for your program, which you'll most certainly use when writing anything of substance in the real world.

Close this file and notice that there's a src/main.rs path/file that the cargo new command created. This is the same Hello, world! program as before. Let's build it with cargo:

cargo build

Now let's run it:

./target/debug/hello_cargo

Let's do the same thing in one command:

cargo run

Use cargo check to compile the code without outputing an executable, as it is much faster than a full compilation of the project!

Ready to release?

Releases are simple and only require the --release flag:

cargo build --release

Now you'll find the executable in ./target/release/hello_cargo instead of ./target/debug/hello_cargo. You can now ship this to all your friends, showing off your expert-level Rust abilities.

Was this page helpful?