Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ahoereth/2607d2ee99103a0a9bc9 to your computer and use it in GitHub Desktop.

Select an option

Save ahoereth/2607d2ee99103a0a9bc9 to your computer and use it in GitHub Desktop.

Tutorial: Meteor in Windows using Vagrant

These days some people were discussing at meteor-talk group about running Meteor at Windows and I’ve recommended them using Vagrant. It’s a very developer-friendly piece of software that creates a virtual machine (VM) which let you run any operating system wanted and connect to it without big efforts of configuration (just make the initial installation and you have it working).

Many packages (I've tested) for running Meteor+Vagrant fails because Meteor writes its mongodb file and also other files inside local build folder into a shared folder between the Windows host and the Linux guest, and it simply does not work. So I've put my brain to work and found a solution: do symlinks inside the VM (but do not use ln. Use mount so git can follow it). It’s covered on steps 8 to 15.

If you have no idea what I’m talking about, I’ve made a tutorial to install Ubuntu Precise x86 through Windows command-line with Meteor very simple to follow:

Requirements

Steps on Windows command-line:

  1. Go to Start Menu > Type cmd > SHIFT + ENTER (to login as Administrator)
  2. cd C:\path\to\your\vagrant+meteor\project\folder
  3. set PATH=%PATH%;C:\Program Files (x86)\Git\bin (Append git binaries to path so vagrant can run ssh)
  4. vagrant init precise32 http://files.vagrantup.com/precise32.box (To install Ubuntu 10.04 x86) Edit the Vagrantfile with your preferred editor and add those two lines anywhere inside the Vagrant.configure(“2”) block:
config.vm.provision :shell, :path => "meteor.sh"
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end

vagrant up (It will download box, configure meteor and get it up) vagrant ssh (It will connect on the VM and expose its command-line) Now that you are inside the VM command-line, you can use it as your server:

Steps on Ubuntu command-line:

. cd /vagrant (This is by default shared with the host) mrt create ~/meteorapp mrt create meteorapp && cd meteorapp && rm -rf .meteor && mkdir .meteor/ (Check your Windows folder you’ve created. It will be there!)

sudo mount --bind /home/vagrant/meteorapp/.meteor/ /vagrant/meteorapp/.meteor/
echo “sudo mount --bind /home/vagrant/meteorapp/.meteor/ /vagrant/meteorapp/.meteor/” >> ~/.bashrc && source ~/.bashrc
mrt run

Go to http://localhost:3000 in Windows browser and see it running! :)

The point here is to use the .meteor folder of your app pointing to another place inside the VM (run ls -la .meteor/ on command-line and you will see the symbolic link), so Meteor uses the VM folder, not Windows folder, and won’t have permissions problems. You will also need to do all git flow inside Ubuntu command-line, because Windows can’t follow those links.

Hints:

  • Make sure you do version control INSIDE THE VM, so the software can follow the symlink.
  • To halt a vagrant VM: vagrant halt
  • To restart a vagrant VM without running all Meteor installation again: vagrant reload --no-provision or just remove the shell path you’ve put on Vagrantfile on line 10.
  • To destroy a VM: vagrant destroy

That’s it. I know it can be improved with chef/puppet or whatever, but this is very simple steps that you can do in less than 30min if you have a fast connection.

Hope you like it, Gabriel Pugliese @gabrielsapo

@dmalik
Copy link
Copy Markdown

dmalik commented Oct 30, 2014

Thanks for this.

@alysdal
Copy link
Copy Markdown

alysdal commented Nov 1, 2014

I needed this, thank you.

@Yathushan
Copy link
Copy Markdown

Hi there I get to step 5 and after editing the config section of the vagrant file, I am still unable to vagrant up. It keeps informing me that my provider "hyper-v" is not supported by trusty 64, which makes sense because this is what is listed in the vagrant cloud.

I am not sure where I am going wrong. Any help would be much appreciated. Thanks

@fongandrew
Copy link
Copy Markdown

@Yathushan, you want to use VirtualBox for your provider, not Hyper-V. If you have already installed VirtualBox, you may also need to change your default provider to VirtualBox (see https://docs.vagrantup.com/v2/providers/default.html) or manually specify the VirtualBox provider by adding --provider=virtualbox to the relevant command.

Note that if you're on Windows 8.1, you may have to disable Hyper-V in order for VirtualBox to work: See https://docs.vagrantup.com/v2/hyperv/index.html.

@Yathushan
Copy link
Copy Markdown

@fongandrew

Thank you very much. I just modified the vagrantfile with ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox' and then after had to modify the base.rb file with regards to a file path and it all worked out fine.

@teadrinker
Copy link
Copy Markdown

Hello, thank you a lot, this worked for me!

Hmm, but how to proceed, I tried messing around with the example, but how do I refresh the app from the server?
The commandline is stuck and does not seem to take any additional commands after (8), ctrl-Z works, and it says "Stopped meteor", however running it again gives me:

Can't listen on port 3000. Perhaps another Meteor is running?

While I can use "ps -x | grep meteor" and "kill -s KILL ..." to get rid of the leftovers, I quite certain I am missing something here concerning refreshing the app from the sources...

EDIT, SOLVED!
Turns out this is a basic Linux Bash thing: ctrl-z just pauses the program, ctrl-c is the one to use!
I did play with linux before, but I guess 15 years has clouded those memories...

@dotnetwise
Copy link
Copy Markdown

nfs without dedicated ip does not seem to actually work -> see this comment
https://gist.github.com/gabrielhpugliese/5855677#comment-1315481

@ahoereth
Copy link
Copy Markdown
Author

ahoereth commented Nov 4, 2014

Mhh nfs worked for me - at least it does not give me any error. Removed it for now, will test it later.

@DiegoAz
Copy link
Copy Markdown

DiegoAz commented Dec 5, 2014

Hi.Thanks, this worked for me.

@gabrieljenik
Copy link
Copy Markdown

Please, find an updated version here.
https://gist.github.com/gabrieljenik/d926cbb90706d95abdee

Pull request work too for gists?

@gabrieljenik
Copy link
Copy Markdown

Has anybody tried to install android mobile platform on the vagrant environment?

@elGusto
Copy link
Copy Markdown

elGusto commented Jan 13, 2015

@gabrieljenik

I did and it works just perfect. I just spent a little while figuring out how to let VB capture the usb port and let adb recognize the device.

@PanArnaud
Copy link
Copy Markdown

It was very useful ! Thank you !

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