如何在 Windows WSL Ubuntu 上安装 Homebrew,并修复“zsh: brew command not found”错误

Som*_*jit 6 windows homebrew windows-subsystem-for-linux ubuntu-20.04

安装是一系列的 5 个简单步骤:

首先,从主页中的命令安装自制软件本身:

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

之后,按照本页中的说明,并更改~/.bash_profile~/.profile因为我使用 Ubuntu 作为我的 wsl 发行版,我必须给出以下命令:

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
Run Code Online (Sandbox Code Playgroud)

但是现在,当我尝试运行 brew 时,command not found出现错误。

Som*_*jit 7

在 wsl 环境中,brew 安装在 location:/home/linuxbrew/.linuxbrew/不是路径的一部分。

所以我们只需要将它添加到路径,它就可以工作。我使用 zsh 作为我的 shell,所以我将这些行添加到我的~/.zshrc文件中(在 ubuntu 文件系统中):

export BREW_HOME="/home/linuxbrew/.linuxbrew/bin"
export PATH="$PATH:$BREW_HOME"
Run Code Online (Sandbox Code Playgroud)