Homebrew can manage command-line packages inside a Linux distribution running under Windows Subsystem for Linux. Installing it in WSL gives Windows users the Linuxbrew package path and keeps brew operations inside the Linux filesystem instead of trying to run Homebrew directly from PowerShell.
The supported Linux and WSL installer uses the default /home/linuxbrew/.linuxbrew prefix. That prefix lets Homebrew use most precompiled packages and keeps later brew install operations from needing sudo after the initial setup.
Use a normal WSL 2 distribution shell, such as Ubuntu or Debian. Ubuntu and Debian WSL distributions use APT packages for the prerequisites; other WSL distributions need equivalent compiler, Git, curl, file, process, and sandbox tools before running the installer.
Related: Set up Windows Subsystem for Linux
Related: How to install a Homebrew formula
PS> wsl.exe --list --verbose NAME STATE VERSION * Ubuntu Running 2
Homebrew recommends WSL 2. Convert an existing WSL 1 distribution before installing when this table shows VERSION 1.
PS> wsl.exe --distribution Ubuntu
$ sudo apt-get update Reading package lists... Done
$ sudo apt-get install build-essential procps curl file git bubblewrap ca-certificates Setting up build-essential (12.12ubuntu2.26.04.1) ... Setting up bubblewrap (0.11.1-1ubuntu0.1) ... Setting up curl (8.18.0-1ubuntu2.2) ... Setting up git (1:2.53.0-1ubuntu1) ...
build-essential provides the compiler toolchain, curl downloads the installer, Git fetches Homebrew, and bubblewrap is part of current Homebrew on Linux dependency checks. Package versions differ by WSL distribution release.
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> This script will install:
/home/linuxbrew/.linuxbrew/bin/brew
/home/linuxbrew/.linuxbrew/share/doc/homebrew
/home/linuxbrew/.linuxbrew/share/man/man1/brew.1
/home/linuxbrew/.linuxbrew/Homebrew
##### snipped #####
==> Installation successful!
==> Next steps:
- Run these commands in your terminal to add Homebrew to your PATH:
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"' >> ~/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"
The installer explains the directories it will create and prompts before making changes during a normal interactive run.
$ eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"
$ echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"' >> ~/.bashrc
Use ~/.zshrc and brew shellenv zsh instead when the WSL distribution uses zsh as the interactive shell.
Related: How to configure Homebrew shell environment
$ command -v brew /home/linuxbrew/.linuxbrew/bin/brew
$ brew --prefix /home/linuxbrew/.linuxbrew
$ brew --version Homebrew 6.0.8
The exact Homebrew version changes over time. The important checks are that command -v brew resolves under /home/linuxbrew/.linuxbrew/bin and brew --prefix prints /home/linuxbrew/.linuxbrew.