Install Rust on macOS with rustup | Generated by AI
Installing Rust using rustup
-
Open Terminal
You can find Terminal in Applications > Utilities or search for it using Spotlight. -
Install rustup and Rust
Run the following command to download and run the rustup installation script:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
The script will prompt you to proceed. Press
1
for the default installation. -
Configure Your Shell
After installation, you may need to add Rust to your systemPATH
. The installer will provide a command similar to:source $HOME/.cargo/env
Add this line to your shell configuration file (e.g.,
.zshrc
,.bashrc
, or.bash_profile
) to make Rust available in future sessions. -
Verify Installation
Check that Rust is installed correctly:rustc --version
You should see the Rust compiler version if the installation was successful.
Using Homebrew to Install Rust
Alternatively, you can use Homebrew to install Rust, though rustup
is generally recommended for easier updates and version management.
-
Install Homebrew (if not already installed):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Install Rust with Homebrew:
brew install rust
-
Verify Installation:
rustc --version
Compiling Rust Code
-
Write a Rust Program
Create a file namedmain.rs
with the following content:fn main() { println!("Hello, World!"); }
-
Compile the Program
In the terminal, navigate to the directory containing your file and run:rustc main.rs
-
Run the Compiled Program:
./main
This setup should get you started with Rust development on macOS. If you have any issues, feel free to ask!