macOS

How to Install the Rust Compiler on macOS

For this tutorial, we will walk you through the process of download and setting up the Rust compiler on your macOS.
Captain Salem 2 min read
How to Install the Rust Compiler on macOS

Rust Lang or Rust is a free and open-source general purpose programming language. It is described as one of the most fast and powerful programming language of our modern age with incredible features such as memory safety without garbage collection.

Rust is mainly known in high performance environments such as compilers, game engines, drivers, operating systems and more. It is also the pioneer in web components and technologies such as web-assembly.

One of the most revolutionary features is that it achieves memory safety without garbage collection allowing low level memory management but still retains security.

Why Rust?

Some of the best features of Rust include:

  1. Cross-platform support.
  2. Ridiculously fast and efficient
  3. Safe memory allocation.
  4. One of the best compilers with helpful error messages and suggestions.
  5. type inference support.
  6. pattern matching
  7. Guaranteed memory safety
  8. Quick and Easy testing and debugging.

Let's dive in.

macOS Install Rust

To install Rust on your macOS, launch your browser and navigate into the resource below;

https://www.rust-lang.org/tools/install

Select the provided installer script and paste it into your terminal.

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

Wait for the download to proceed and you'll see an output as shown:

Select 1 to proceed with installation.

The installer will download all the required packages and install them on your system.

Finally, run the command:

source "$HOME/.cargo/env"

Once completed, you can verify the rust compiler is installed using the rustc command as shown:

rustc --version

The command will return an output as shown:

rustc 1.62.1 (e092d0b6b 2022-07-16)

Simple Rust Program

To get started with rust, we can create a simple hello world program.

Start by creating a file ending in .rs file:

touch hello.rs

Edit the file;

nano hello.rs

Add the hello world code as shown:

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

Save the file and close.

Finally, compile the program with the command:

rustc hello.rs

Once compilation is complete, you can run the program:

./hello

Output:

Hello world

And with that, you have successfully installed the Rust compiler on macOS and compiled a simple hello world program.

Conclusion

We hope you enjoyed this tutorial, stay tuned for more and feel free to share or leave a comment down below.

Thanks for reading!

If you enjoy our content, please consider buying us a coffee to support our work:

Share
Comments
More from GeekBits

Join us at GeekBits

Join our members and get a currated list of awesome articles each month.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to GeekBits.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.