How to get rid of the default shared folder in Vagrant?

Vagrant is awesome. However, there’s one thing that really annoys me. Why in the world does it set up a default shared folder when no one asks it to. After some googling, I found out that all you have to do is to add the following line in your Vagrant file.


Vagrant.actions[:start].delete(Vagrant::Action::VM::ShareFolders) # <--add this line
Vagrant::Config.run do |config|

Unfortunately, there’s one more gotcha. The first time I ran vagrant up, it crapped out on me and spilled out the following stacktrace.


/opt/vagrant/embedded/gems/gems/vagrant-1.0.6/lib/vagrant/action/builder.rb:87:in `delete_at': no implicit conversion from nil to integer (TypeError)
from /opt/vagrant/embedded/gems/gems/vagrant-1.0.6/lib/vagrant/action/builder.rb:87:in `delete'
from /home/lih/.vagrant.d/boxes/lucid32/include/_Vagrantfile:6:in `<top (required)>'
from /home/lih/.vagrant.d/boxes/lucid32/Vagrantfile:11:in `load

I sidestepped the above issue by surrounding it with begin and rescue.


begin
  Vagrant.actions[:start].delete(Vagrant::Action::VM::ShareFolders)
rescue
  print "Trying to get rid of the default shared folder. It's normal that this fails the first time when the vm is booted up. Ignore and proceed."
end

Hopefully, you’ll find this helpful. Enjoy.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: