Skip to content

Instantly share code, notes, and snippets.

@Jakobud
Last active July 28, 2017 21:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Jakobud/0768ff6b6051e79eef60 to your computer and use it in GitHub Desktop.
Save Jakobud/0768ff6b6051e79eef60 to your computer and use it in GitHub Desktop.
Vagrant Windows 260 character path limit workaround
# If you are using Windows as your Vagrant host OS, there is a limitation in Windows where any given folder path
# cannot be more than 260 characters long. This becomes a problem with Vagrant because, for example, if you
# install a Linux guest environment and try to create a deep directory structure in a synced folder, Linux will
# throw errors. This is because the synced folder is under the constraints of the Windows host. A common example
# of this happening is when installing node.js modules. NPM is known for creating some very long, deep
# folder paths because each node depenency has it's own dependencies, which have their own dependencies, etc...
#
# This gist solves the problem and works around the Windows 260 character path limit. Add it to your Vagrantfile.
#
# NOTE: This bug in Vagrant was fixed in 1.7.3, but reverted back in 1.7.4 due to some regression bugs.
# First, disable default vagrant share
config.vm.synced_folder ".", "/vagrant", disabled: true
# Next, setup the shared Vagrant folder manually, bypassing Windows 260 character path limit
config.vm.provider "virtualbox" do |v|
v.customize ["sharedfolder", "add", :id, "--name", "vagrant", "--hostpath", (("//?/" + File.dirname(__FILE__)).gsub("/","\\"))]
v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"]
end
# Finally, mount the shared folder on the guest system during provision
config.vm.provision :shell, inline: "mkdir -p /vagrant", run: "always"
config.vm.provision :shell, inline: "mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant", run: "always"
# Now you have a /vagrant folder on your Linux environment that does not have the Windows 260 character path limit issue
@ashley200
Copy link

Try Long path tool. Its more easier than this long coding method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment