How to install Homebrew on Windows

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
4 min

banner

# Table of Contents

  1. Installing Homebrew on Windows using Windows Subsystem for Linux (command line)
  2. Installing Homebrew on Windows using Windows Subsystem for Linux (Microsoft Store)
  3. Installing Chocolatey - a Homebrew alternative for Windows

# How to install brew on Windows

The 3 most common options for installing Homebrew on Windows are:

  1. Using Windows Subsystem for Linux with a command line installation.
  2. Using Windows Subsystem for Linux with a Microsoft Store installation.
  3. Installing Chocolatey - a brew alternative for Windows.

# Installing Homebrew on Windows using Windows Subsystem for Linux (command line)

To install Windows Subsystem for Linux and Homebrew on Windows:

  1. Click on the Search bar and type CMD.

  2. Right-click on the Command Prompt application and click "Run as administrator".

run cmd as administrator

  1. Issue the wsl --install -d Ubuntu command.
cmd
wsl --install -d Ubuntu

wsl install ubuntu

  1. You can use the wsl --list --online command if you want to list all valid distributions that can be installed.
cmd
wsl --list --online # 👇️ the syntax for the installation command wsl --install -d DISTRO_NAME

wsl list online

  1. If you get an error that the wsl command is not recognized, use the older lxrun command instead.
cmd
lxrun /install
  1. You will be prompted to enter a new UNIX username and Password. Make sure to remember your credentials.

create default unix account

  1. Wait for the installation to complete.

wait for installation to complete

  1. Close your CMD and PowerShell sessions and reopen your shell as an administrator.

  2. Now you can simply type bash in CMD to start a bash shell.

Run the following commands.

cmd
bash sudo apt-get update sudo apt-get install build-essential procps curl file git

start bash shell

Now you can use the following command to install Homebrew.

cmd
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

wsl-install-brew

Make sure to use the bash command to enter a bash session before issuing Unix commands.
  1. Use the following commands to add Homebrew to your PATH.
cmd
test -d ~/.linuxbrew && eval "$(~/.linuxbrew/bin/brew shellenv)" test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" test -r ~/.bash_profile && echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bash_profile echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.profile

add homebrew to path

  1. Now you should be able to use brew.
cmd
brew install hello

brew install hello

  1. You can also click on the Search bar and type "Ubuntu" to start your integrated Linux environment.

windows start ubuntu

# Installing Homebrew on Windows using Windows Subsystem for Linux (Microsoft Store)

To install Windows Subsystem for Linux and Homebrew using Microsoft Store:

  1. Click on the https://aka.ms/wslstore link.

  2. In the Microsoft Store window, use the Search bar to look for your Linux distribution of choice. For example, Ubuntu 22.04.1 LTS.

search for linux distribution

  1. Click on your preferred Linux distribution and use the "Get" button to install it.

click get button

  1. Wait for the installation to complete.

wait for linux installation to complete

  1. Once the installation is complete, click on the "Open" button.

click open button

  1. A console window will launch and you will be prompted for a username and a password. Make sure to remember your credentials.

enter your credentials

After the process is complete, you can click on the Search bar and type "Ubuntu" to start your integrated Linux environment.

windows start ubuntu

Now you can simply type bash in CMD to start a bash shell. Run the following commands.

cmd
bash sudo apt-get update sudo apt-get install build-essential procps curl file git

start bash shell

Now you can use the following command to install Homebrew.

cmd
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

wsl-install-brew

Make sure to use the bash command to enter a bash session before issuing Unix commands.
  1. Use the following commands to add Homebrew to your PATH.
cmd
test -d ~/.linuxbrew && eval "$(~/.linuxbrew/bin/brew shellenv)" test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" test -r ~/.bash_profile && echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bash_profile echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.profile

add homebrew to path

  1. Now you should be able to use brew.
cmd
brew install hello

brew install hello

# Installing Chocolatey - a Homebrew alternative for Windows

To install Chocolatey, a Homebrew alternative for Windows:

  1. Open PowerShell as an administrator.

run powershell as administrator

  1. Run the following command.
PowerShell
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

windows install chocolatey

  1. Wait for the command to complete.
  2. Type choco to make sure Chocolatey is installed.

windows verify chocolatey installed

Now that Chocolatey is installed, you can install a package with the choco install command.

Here is an example command that installs wget.

PowerShell
choco install wget -y

chocolatey install wget

Note that your shell should still be run using elevated permissions.

Now you should be able to use the wget command.

shell
wget https://google.com -o out.html

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.