11

Installation was a series of 5 simple steps:

first, install homebrew itself from command in the home page:

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

After that, following instructions in this page, and changing ~/.bash_profile to ~/.profile as I am using Ubuntu as my wsl distro, i had to give these commands:

test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile

But now, when I try to run brew, I get command not found error.

Somjit
  • 2,503
  • 5
  • 33
  • 60

2 Answers2

34

In a wsl environment, brew is installed at location: /home/linuxbrew/.linuxbrew/ which is not part of the path.

So we simply need to add that to path, and it works. I am using zsh as my shell, so I add these lines to my ~/.zshrc file (in ubuntu file system) :

export BREW_HOME="/home/linuxbrew/.linuxbrew/bin"
export PATH="$PATH:$BREW_HOME"
Somjit
  • 2,503
  • 5
  • 33
  • 60
0

if you happen to need to share your .zshrc across different OS, you can do some OS check in your zshrc file to see if it is macOS or linux/wsl:

case `uname` in
  Linux)
    ## add brew home to PATH in linux/WSL
    brew_home=/home/linuxbrew/.linuxbrew
    if [ -d "${brew_home}" ]; then
      export PATH=${brew_home}/bin:$PATH
    fi

    javac_loc=/usr/bin/javac
    if [ -x "$javac_loc" ]; then
      export JAVA_HOME=$(readlink -f $(dirname $(readlink -f $javac_loc)))
    fi
  ;;
  Darwin)
    ## Do macOS thing...
    export JAVA_HOME=$(/usr/libexec/java_home)
  ;;
esac

LeOn - Han Li
  • 9,388
  • 1
  • 65
  • 59