0

我正在使用这个流浪文件:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "ubuntu/trusty64"

  ...bla bla bla bla bla...

    config.vm.provision "shell", path: "provision/setup.sh"

end

因为我想安装 Linuxbrew,所以我在我的provision/setup.sh中有这个代码:

sudo apt-get update

sudo apt-get install --yes git-all libreadline-dev build-essential curl git m4 python-setuptools ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"

# or maybe also this: (but nothing anyway):
# sudo git clone https://github.com/Linuxbrew/linuxbrew.git /home/vagrant/.linuxbrew

export PATH=$HOME/.linuxbrew/bin:$PATH

brew doctor

但我检索错误:

==> default: /tmp/vagrant-shell: line 35: brew: command not found

如何解决这个问题?

4

2 回答 2

1

让我猜猜。yes在 ruby​​ 命令之前添加

yes | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
于 2016-02-03T12:28:53.533 回答
1

运行脚本的方式存在问题-使用config.vm.provision "shell", path: "provision/setup.sh"vagrant 运行时将以root用户身份运行它,因此您不需要 sudo

但是你真的应该以你的用户身份运行它config.vm.provision "shell", path: "provision/setup.sh", privileged: false

也不会为您将来的会话保存导出,因此将其添加到.bashrc文件中,echo PATH=$HOME/.linuxbrew/bin:$PATH >> .bashrc这样最终脚本看起来像

sudo apt-get update
sudo apt-get install --yes git-all libreadline-dev build-essential curl git m4 python-setuptools ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev

yes | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"

echo PATH=$HOME/.linuxbrew/bin:$PATH >> ~/.bashrc    
export PATH=$HOME/.linuxbrew/bin:$PATH
brew doctor

如果您从脚本运行 brew ,则需要导出,但请注意 brew doctor 可能会以警告结束并且不会返回,因此您最终可能会看到 vagrant 消息为

The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

最后对于原始错误,@BMW 获得所有添加yes |到命令的功劳将默认输入问题上的键

于 2016-02-03T13:28:26.727 回答