Getting Started With Rust
There are a few ways to get started with Rust. This page covers how to install, update, troubleshoot, and uninstall Rust.
The easiest option is to use a browser based Rust playground that we can use to play with and learn the language. However, we will eventually want to install Rust locally and gain the full power of the language.
Rust Playground
The Rust playground allows us to write, run, build, debug, and test Rust code without requiring any installation. It’s a great way to quickly tinker with Rust code, and it can be used on systems that you can’t install Rust on, like a school or a library computer.
Installing Rust
The standard methods for installing Rust all use Rustup. Rustup is an installer and version management tool. After installing Rust, you may need to install a linker for it to function correctly (see below).
Note: Rust installation is a bit different depending on the OS. MacOS and Linux share the same installation instructions, but things are a little different on Windows. Windows users also have the option of installing with WSL (Windows Subsystem for Linux).
Installing Rust on MacOS or Linux
On Linux or MacOs, enter the following command into a terminal:
curl –proto ‘=https’ –tlsv1.3 https://sh.rustup.rs -sSf | sh
To complete the installation, select an installation option (default recommended):
Installing Rust on Windows
There are 32-bit and 64-bit version installers for Windows machines at https://www.rust-lang.org/tools/install
Alternatively, WSL users can also install Rust using the Linux command in the WSL prompt:
curl –proto ‘=https’ –tlsv1.3 https://sh.rustup.rs -sSf | sh
Installing a Linker – MacOS, Linux, WSL
Rust requires a linker, which is a program that Rust will use to combine its outputs into a single file. If you get linker errors, the simplest way to resolve them is by installing a C compiler.
On Linux and WSL, the easiest way to do this is to get gcc or clang using a package manager your Linux distribution. On Ubuntu machines, we can use the build-essential package using the following command:
sudo apt install build-essential
On MacOs you can use the following command to install a C compiler:
xcode-select –install
Check Rust Version
To verify install and/or check the version of Rust that is currently installed, we can use the command:
rustc –version
Updating Rust
Once rustup is installed, we can use it to easily update Rust via the command:
rustup update
Uninstalling Rust
Rust can be uninstalled using the following command:
rustup self uninstall
Troubleshooting Rust Installation
If installation completed but Rust isn’t working, the issue is likely your $PATH variable.
The $PATH variable is a list of directories that contain the commands that we want to run on the command line. In this case, we want to run the command rustc – we need to make sure that our computer knows where to look for the code that corresponds to the rustc command.
You can check the $PATH variable using the following commands.
Check $PATH on Linux/MacOS/WSL:
echo $PATH
Check $PATH in Windows Powershell:
echo $env:Path
Check $PATH in Windows CMD:
echo %PATH%
In each case, you are looking for the directory that contains rustc.