In this section, you will:
- Install Rust and its dependencies
- Learn what
- Get your local machine environment ready for Rust development
Setting up Your Environment
There is a standard tool in the Rust ecosystem called
rustup. This tool allows you to easily
install and manage multiple Rust versions and use different Rust versions on a per-project basis. It
is similar to a tool like
to managing the version of Rust itself, it also installs
cargo, the Rust build tool, and various
language components such as different target architectures, and clippy, the Rust linting tool.
rustup, run this install script below:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
This is executing a script from the internet, so if you prefer to be careful, check its contents to ensure it isn't doing anything unwanted. This line of code installs several tools:
rustup, which was covered above,
cargo, the Rust package manager, and
rustc, the official compiler for the Rust language.
Executing the line of code above will prompt the installation options below:
Current installation options:
default host triple: x86_64-apple-darwin
default toolchain: stable (default)
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
Select Option 1 for the standard install. We will add more components later in the course as
needed. When the command completes, you can confirm that rustup is installed by checking its version
$ rustup self update
info: checking for self-updates
rustup unchanged - 1.25.2
We can also check the version of the rust compiler and the cargo build tool.
$ rustc --version
rustc 1.68.0 (a55dd71d5 2022-09-19)
$ cargo --version
cargo 1.68.0 (387270bc7 2022-09-16)
This course will use version 1.68, but similar versions will work just as well.
You can update your toolchains at any time by running
rustup update, and you can even update
rustup itself by running
rustup self update.
Visual Studio Code
The most commonly-used (and recommended) tool to use for Rust is Visual Studio Code (also called VS Code) with the Rust analyzer, which can be installed as a VS Code extension. Throughout the course, VS Code will be the primary editor of choice. Please head to https://code.visualstudio.com/download to install VS Code.
There are other acceptable text editors and integrated development environments also available. Atom IDE-Rust may also be used.
If you prefer an open source and freely-licensed distribution of VS Code that omits telemetry, VSCodium is also viable. See the project's installation site and the reason why you might want to use this over VS Code itself.
Once VS Code is installed, there are a couple of extensions that will smooth the development experience.
The first extension we'll add is Rust Analyzer, a powerful static analysis tool for the Rust programming language. This extension provides some basics such as syntax highlighting and goto definition, as well as more powerful features such as code completion and documentation by hovering over code.
To install it, enter VS Code's command pallet with
Ctrl + Shift + P, and paste:
ext install rust-lang.rust-analyzer
The second extension is optional but recommended if you like to do step debugging on your coding
projects. It is the Code LLDB extension that provides seamless integration between LLDB, the
low-level debugger, and VS Code. To install it, enter the command pallet again (
Ctrl + Shift + P)
ext install vadimcn.vscode-lldb
We will not use this extension actively in this course, but it is a great tool to have handy when it comes time to debug your own code.
The Rust Playground
The Rust playground is an in-browser implementation of a Rust development environment. Feel free to use it to run snippets of code if setting up a proper development environment is somehow inaccessible. Throughout this course, you will notice it embedded within the page as follows:
You may also visit it at https://play.rust-lang.org/.