问题
I want to set up vagrant on my Ubuntu, when "vagrant up", it always give me the following error syntax error, unexpected ':', expecting kEND config.vm.provision :shell, path: "vagrantprov.sh"
I checked the Vagrantfile, it should be OK, can anyone tell me where the error is? Thanks.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
end
config.vm.provision :shell, path: "vagrantprov.sh"
end
回答1:
What version of Ruby are you running? The named args syntax (path: "..."
) is supported from on 1.9 and above, perhaps you have a lower Ruby version?
(1.8)
1.8.7 :001 > puts "a", b: 1
SyntaxError: compile error
(irb):1: syntax error, unexpected ':', expecting $end
(1.9)
1.9.3p429 :001 > puts "a", b: 1
a
{:b=>1}
=> nil
回答2:
Ruby <1.9? Old fashioned hash syntax style is required for old Ruby version
config.vm.provision :shell, :path => "vagrantprov.sh"
回答3:
Ruby < 1.9 :
:a => 1
Ruby >= 1.9 :
a : 1
来源:https://stackoverflow.com/questions/26556683/ruby-unexpected-expecting-kend