Vagrant Setup

Vagrant Setup

We need an easily-repeatable setup for developers environment.

Dev Version / installing Vagrant from source: https://github.com/mitchellh/vagrant/wiki/Installing-Vagrant-from-source

Vagrant Install

If you have already installed Ruby on Windows, the procedure should be different. But, for Ruby newbies like me, this way is the best.

Download and install .MSI file. http://downloads.vagrantup.com/ :: Vagrant - Downloads Try not to use “Program Files” or any directory with whitespace in it’s name.

Sometimes, the bug with ‘path with whitespaces’ can trigger win Windows. Reason: Windows names can have spaces in it… :( Error message: WARNING Libtool does not cope well with whitespace in pwd Easily solvable by installing in directory without whitespace in name.

Update PATH variable and VAGRANT_HOME, and make them permanent. Look at bugs #1 and #2 later, for the reason why I’m doing this right now.

The installer automaticly added \vagrant\bin to the end of system Path, and I will add some more by typing:

<vag-dir>\vagrant\embedded\devkitvars.bat
setx path "%PATH%" /m
setx VAGRANT_HOME "s:\vagrant\.vagrant.d"

Now go to your Git directory.

Sources: https://github.com/mitchellh/vagrant/issues/817 :: Issue #817: Wrong DevKit PATH in operating_system.rb · mitchellh/vagrant

Vagrant Usage

Start VM with vagrant up or without provisioning: vagrant up <OurVmName> --no-provision

Connect to VM with vagrant ssh This will work on Linux, but on Windows (using your preferred SSH client), you’ll get info by typing “vagrant ssh”

Really (force) remove and delete of VMs with vagrant destroy -f


Err: The box ‘lucid32’ could not be found. S: vagrant box add lucid32 http://files.vagrantup.com/lucid32.box

Install Vagrant on Windows

michaelklapper/DevOps · GitHub

Check that Ruby is installed and it’s in a path (rubyinstaller.org).

DevKit install

Download and unpack archive to “C:\DevKit” directory: https://github.com/oneclick/rubyinstaller/downloads/ :: Downloads · oneclick/rubyinstaller Latest is: https://github.com/downloads/oneclick/rubyinstaller/DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe

Execute in directory where file is downloaded:

set DEVKIT_INSTALL_DIR=%SYSTEMDRIVE%\DevKit DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe -o"%DEVKIT_INSTALL_DIR%" -y

%SYSTEMDRIVE% cd “%DEVKIT_INSTALL_DIR%” ruby dk.rb init ruby dk.rb install –force

Now, Vagrant would install. Go to command prompt, type and wait: gem install vagrant

And, that’s it.

Note:

I explored every possible way of installing Vagrant as is recommended. Recommended way is to support Veewee Gem install, “vagrant ssh”, etc. Tried the following: Vagrant Setup Exe for Windows, Vagrant thru Chocolatey, etc.

It turns out, none of them worked. Usually DevKit was problem or PATH or anything similar. The only way to make it work is like I explained before - manually.

The simplest way

Install Vagrant. Choose “c:", not “c:\vagrant”. This is because I don’t like duplicated path parts like: c:\vagrant\vagrant... So, I will asume that is “c:"

Remove “c:\vagrant\bin” from the PATH. Do it manually. This is a-must. It’s at the end of System Path (not User Path) - the System is executed before User.

Setup variables as: set PATH=c:\vagrant\embedded\bin;%PATH%;c:\vagrant\embedded\mingw\libexec\gcc\mingw32\4.5.2 set VAGRANT_HOME=s:\home\vagrant

and make them permanent: setx PATH “%PATH%” /m setx VAGRANT_HOME “%VAGRANT_HOME%” /m

It is very important that the first path to search is: c:\vagrant\vagrant\embedded\bin
We need that Vagrant should be called from that path.

Last directive is (see research on GEM_PATH and GEM_HOME): set GEM_PATH=c:/vagrant/embedded/lib/ruby/gems/1.9.1;s:/home/vagrant/gems setx GEM_PATH “%GEM_PATH%” /m

From now on, you will install Vagrant plugins as normal: gem install vagrant-screenshot gem install veewee gem install vagrantboxes

\vagrant\embedded\devkitvars.bat (needed for compiling Veewee Gem) setx path “%PATH%” /m setx VAGRANT_HOME “s:\vagrant.vagrant.d” (location of user-specific files)

  • Veewee wiil not work with: vagrant gem install veewee

  • x

Vagrant LAMP

Puppet Recipes

In a dedicated Puppet file.


Vagrant installs embedded Ruby environment (with RubyGems), and Gems can be installed with “vagrant gem” command.

A bug #1: https://github.com/mitchellh/vagrant/issues/817 :: Issue #817: Wrong DevKit PATH in operating_system.rb · mitchellh/vagrant

Because of a bug, you must manually setup PATH before doing any RubyGems commands. \vagrant\embedded\devkitvars.bat

Because we need this new path permanently, after checking it’s ok, let’s make it sticky: setx path “%PATH%” /m

And #2: we should immediately prevent bug #2 mentioned later, with permanently setting:

setx VAGRANT_HOME "s:\vagrant\.vagrant.d"
Btw, you should move this folder (default was: ~/.vagrant.d)
because in it Vagrant stores downloaded baseboxes, along with the other stuff.

Note that you MUST restart command line instance before the change takes effect. Note that on old Windows instead SETX command, you must use alternative syntax or do it manually: http://superuser.com/questions/135056/set-permanent-environmental-variable-in-windows-xp :: script - Set Permanent Environmental Variable in Windows XP - Super User

So, do this to update Gems: gem update –system


The differences:

  • vagrant gem env

    • INSTALLATION DIRECTORY: s:/home/vagrant/gems
    • EXECUTABLE DIRECTORY: s:/home/vagrant/gems/bin
    • GEM PATHS:
      • s:/home/vagrant/gems
      • s:/home/vagrant/gems:
  • gem env

    • INSTALLATION DIRECTORY: c:/vagrant/embedded/lib/ruby/gems/1.9.1
    • EXECUTABLE DIRECTORY: c:/vagrant/embedded/bin
    • GEM PATHS:
      • c:/vagrant/embedded/lib/ruby/gems/1.9.1
      • C:/Users/Colovic Vladan/.gem/ruby/1.9.1

I tried

set GEM_HOME=c:/vagrant/embedded/lib/ruby/gems/1.9.1 set GEM_PATH=c:/vagrant/embedded/lib/ruby/gems/1.9.1;s:/home/vagrant/gems

It looks like Vagrant’s GEM is ignoring GEM_HOME and GEM_PATH variables. So, forget about it.

Only GEM_PATH directive has good effect, but only on standalone non-Vagrant GEM. set GEM_PATH=c:/vagrant/embedded/lib/ruby/gems/1.9.1;s:/home/vagrant/gems

***

***

You could put VBoxManage.exe in path: set path=%path%;c:\Program Files\Oracle\VirtualBox

***

Everything is called from embedded Ruby, specially RubiGems: The location is c:\vagrant\vagrant\embedded\bin\

c:\vagrant\vagrant\embedded\bin\gem install sahara-0.0.11.gem

***

Windows problems bible https://github.com/oneclick/rubyinstaller/wiki/Troubleshooting#wiki-gems_win7 :: Troubleshooting · oneclick/rubyinstaller Wiki · GitHub

Real good manual installation https://github.com/zeljkofilipin/watirbook/blob/master/installation/windows.md :: watirbook/installation/windows.md at master · zeljkofilipin/watirbook · GitHub

latest Windows version: http://www.ruby-forum.com/topic/3994497#1055173 :: Ruby on Windows. - Ruby Forum

Symlink problem with shared folders (not NFS & CIFS)

Problems & Solutions

P: Symlinks problem: The VirtualBox shared folder filesystem doesn’t allow symlinks, unfortunately. http://stackoverflow.com/questions/9150732/capistrano-deploy-in-virtual-machne :: ruby on rails - Capistrano deploy in Virtual Machne - Stack Overflow S: in link http://blog.liip.ch/archive/2012/07/25/vagrant-and-node-js-quick-tip.html :: Liip Blog // Vagrant and Node.js quick tip

Bridged networking very slow

Wireless Bridged Networking is very slow. Maybe the reason is IPv6 and not the Wireless? Why is VirtualBox Bridged networking slow

Try to improve with Virtio drivers? Conclusion: Must use Virtio drivers.

List of vagrant VM options?

Vagrant options that can be specified for virtal machines:

"c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm | grep something

Virtual Machine Automation with Vagrant

Execution Timing in Windows

Measure execution time:

cmd /v:on /c "set _s=!TIME! & vagrant up & echo Elapsed time: !_s! - !TIME!"

The problem is evaluation of variables. This is why we have /v:on switch.

Ruby vs Vagrant

I don’t want to have any Ruby environment. So, don’t add vagrant\embedded\bin\ to the path, at all. But, in any case, set some variables, if you ever install some gem.

for /f "tokens=*" %f in ('vagrant gem env gemhome') do @(set _CURGEM=%f)

set _TMP=C:\Tools\Vagrant\vagrant\embedded\lib\ruby\gems
for /f "tokens=*" %f in ('dir "%_TMP%" /B /A:D') do @(set _VAGGEM=%_TMP%\%f)

set GEM_HOME=%VAGRANT_HOME%\gems
set GEM_PATH=%GEM_HOME%;%_CURGEM%;c:\vagrant\embedded\gems\gems;%_VAGGEM%

ree -u GEM_HOME "%GEM_HOME%"
ree -u GEM_PATH "%GEM_PATH%"

set PATH=%PATH%;%GEM_HOME%\bin
ree -a -c -m PATH "%GEM_HOME%\bin"

We need to close console, because some environment variables are not propagated, because they are in a System environment. So, again, start the command prompt.

date 01. Jan 0001 | modified 28. May 2021
filename: Vagrant - Setup