How to install Brew on WSL- Windows subsystem for Linux

Homebrew or simply Brew is the package management tool developed under open source license. The main purpose of Brew is to install various software on macOS, however, it is not limited to that only. Yes, we can install it on Linux Distros and Windows 10 using the WSL- Windows system for Linux.

Here in the article, we will learn the steps to set up Brew on Windows 10 WSL to install various packages…

HomeBrew installation on Windows 10- WSL (Windows Subsystem for Linux)

Before starting the tutorial, I am assuming that you already have the WSL with Ubuntu on your Windows 10 or server system. If not then follow the tutorial: Steps to enable WSL with Ubuntu.

Open Ubuntu WSL App

Currently, there are two long term Ubuntu versions available on Microsoft Store to install: Ubuntu 18.04 LTS & Ubuntu 20.04 LTS Linux. You can opt for any of them, the steps given here will be the same. Therefore, whatever the Linux version you have on your Windows 10, open that.

Run Update command:

To make sure the Packages and Repos available on your Linux WSL app are up to date, just run a system update command:

sudo apt update

Install tool require to setup Brew

There are few tools that we need to have on the system such as curl in order to download and install HomeBrew on our WSL 1 or 2 Linux apps. Therefore run below command with sudo access.

sudo apt-get install build-essential curl file git

Command to Install HomeBrew on WSL Windows 10

Once you down with the above step, now here is the script that is available on Github to install Brew instantly on Windows Subsystem for Linux. Just copy and paste the below command in your Ubuntu WSL Linux app.

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

Add Homebrew to your system PATH

By default, you won’t be able to run Brew without switching to the directory where it has been installed. Thus, to use it from anywhere regardless of which directory you are, we need to tell the Ubuntu WSL Linux app about it by adding it to the bin. Run the following commands on your Linux system one by one.

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

Use Brew on WSL

Finally, this Package Manager is successfully installed on your system, now its time to see whether it is working or not. For that let’s use the brew to install the git on our system. The command will be:

brew install package-name

brew install git

To update it, use:

brew update

To get the info about any package:

brew info python

To learn more about its commands see the official documentation. 

Install Homw Bre w on Windows 10 WSL Windows subsystem for Linux min

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.