- 1 year ago
How to Install Homebrew on Windows WSL Ubuntu, and fix "zsh: brew command not found" error
Homebrew is primarily designed for macOS and does not have official support for Windows. However, you can use the Windows Subsystem for Linux (WSL) with Ubuntu to install and use Homebrew-like package managers such as Linuxbrew or WSLbrew.
Here's how you can install and use Linuxbrew/WSLbrew on WSL Ubuntu and fix the "zsh: brew command not found" error:
Open the Ubuntu terminal on WSL.
Update your system's package lists by running the following command:
bashsudo apt update
Install the required dependencies using the following command:
bashsudo apt install build-essential curl file git
Install Linuxbrew/WSLbrew by running the following command:
bashsh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
Follow the instructions provided during the installation process. By default, Linuxbrew/WSLbrew will be installed to
~/.linuxbrew
.Once the installation is complete, you need to add the necessary environment variables to your shell configuration file (
~/.bashrc
,~/.zshrc
, etc.). Open the file using a text editor:bashnano ~/.bashrc
Add the following lines at the end of the file:
bashexport PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
Save the file and exit the text editor.
Close and reopen your terminal, or run the following command to apply the changes to your current session:
bashsource ~/.bashrc
Verify the installation by running the following command:
bashbrew --version
If Homebrew (Linuxbrew/WSLbrew) is installed correctly, you should see the version information.
Now you should be able to use Homebrew-like package management on WSL Ubuntu. However, please note that not all macOS-specific packages available through Homebrew may be available through Linuxbrew/WSLbrew. You may need to adjust your package installation commands accordingly.
If you encounter any issues, refer to the official documentation for Linuxbrew/WSLbrew for further guidance and troubleshooting.