Vagrant provision shell,使用命令自动安装 Linuxbrew
Vagrant provision shell, auto install Linuxbrew with command
我正在使用这个 vagrantfile:
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
如何解决这个问题?
让我猜猜。在ruby命令前添加yes
yes | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
你如何 运行 你的脚本有一个问题 - 因为你 运行 和 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 可能会以警告结束而不是 return 所以您最终可能会看到 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 |
将默认输入问题的回车键
我正在使用这个 vagrantfile:
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
如何解决这个问题?
让我猜猜。在ruby命令前添加yes
yes | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
你如何 运行 你的脚本有一个问题 - 因为你 运行 和 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 可能会以警告结束而不是 return 所以您最终可能会看到 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 |
将默认输入问题的回车键