Setup Rust & Haskell on macOS
Setup Rust & Haskell on macOS
If you’re diving into systems programming with Rust or exploring the world of functional programming with Haskell, the first step is getting your development environment properly configured. This guide walks you through the setup process for both languages on macOS, including installing toolchains, configuring shell settings, and compiling a simple “Hello, World!” program.
🦀 Setting Up Rust on macOS
Rust provides a dedicated installer called rustup, which manages the compiler (rustc
), Cargo (Rust’s package manager), and different toolchains.
1. Install Rust with rustup
The recommended way is via the official script at rustup.rs:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Follow the prompts to install the stable Rust toolchain.
2. Update and Check Installation
After installation, update your toolchain and confirm:
rustup updaterustup show
You can also list installed Cargo binaries:
cargo install --list
3. Configure Your Shell
To ensure Rust tools are available in your terminal, add the following to your ~/.zshrc
file:
. "$HOME/.cargo/env"
Reload your shell with source ~/.zshrc
.
4. Compile and Run a Program
Create a file named hello-world.rs
:
fn main() { println!("Hello, World!");}
Compile and run it:
rustc hello-world.rs./hello-world
You should see:
Hello, World!
λ Setting Up Haskell on macOS
For Haskell, the recommended toolchain manager is GHCup, which simplifies installation of GHC (the compiler), Cabal, Stack, and Haskell Language Server.
1. Install GHCup
Using Homebrew, install GHCup from haskell.org:
brew install ghcup
2. Install Tooling
Use GHCup to install and set the latest recommended versions:
ghcup install ghc --setghcup install cabal --setghcup install hls --setghcup install stack --set
Check installed components:
ghcup list -c installed
3. Configure Your Shell
Add GHCup’s binaries to your PATH in ~/.zshrc
:
export PATH="$HOME/.ghcup/bin:$PATH"
Reload with source ~/.zshrc
.
4. Compile and Run a Program
Create a file named hello-world.hs
:
main = putStr "Hello, World!\n"
Compile and run:
ghc hello-world.hs./hello-world
You should see the output:
Hello, World!
Conclusion
With both Rust and Haskell installed, you’re now ready to:
- Use Cargo for Rust project management and package handling.
- Use Cabal or Stack for Haskell project builds.
- Leverage powerful type systems and expressive languages for different programming paradigms.
Whether you’re exploring safe systems programming with Rust or functional purity with Haskell, your macOS machine is now set up for the journey.