How to install rust in MacOS, Linux, and Windows
Here are the steps to install Rust on macOS, Linux, and Windows:
MacOS and Linux
-
Open Terminal.
-
Run the installation script: Use the following command in your terminal [1]:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
This command downloads and executes the
rustup
script, which is the official Rust installer [1]. -
Follow the on-screen instructions: The script will guide you through the installation process. It will ask you to confirm the installation and configure your environment.
-
Configure the
PATH
environment variable:rustup
will attempt to configure yourPATH
environment variable during installation. If it doesn't succeed, you may need to manually add the Rust toolchain directory to yourPATH
. The toolchain is typically located in~/.cargo/bin
[1]. You can modify your shell's configuration file (e.g.,.bashrc
,.zshrc
) to include the following line:export PATH="$HOME/.cargo/bin:$PATH"
-
Verify the installation: After the installation is complete, open a new terminal and run the following command:
rustc --version
This will display the installed Rust version, confirming that Rust is installed correctly and accessible from your terminal [1].
Windows
-
Download the installer: Download the appropriate
rustup-init.exe
installer (32-bit or 64-bit) from the official Rust website [1]. -
Run the installer: Execute the downloaded file and follow the on-screen instructions. You might be prompted to install the Visual Studio C++ Build tools [1].
-
Configure the
PATH
environment variable:rustup
should automatically configure thePATH
environment variable during installation. If it doesn't, you'll need to add%USERPROFILE%\.cargo\bin
to yourPATH
manually [1]. -
Verify the installation: Open a new command prompt or PowerShell window and run:
rustc --version
This will display the installed Rust version [1].
Additional Notes
-
Windows Subsystem for Linux (WSL): If you are using WSL, you can install Rust using the same command as in macOS and Linux [1]:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Other Installation Methods: While
rustup
is the preferred method, Rust can also be installed via other methods [1]. -
Homebrew (macOS): You can also use Homebrew to install Rust on macOS [5]:
brew install rust
-
Uninstalling Rust: To uninstall Rust, you can run
rustup self uninstall
[1].