Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tutorial for running Meteor in Windows using Vagrant

Tutorial: Meteor in Windows using Vagrant

BEFORE YOU CONTINUE:

  • Now, Meteor runs in any Windows without any line of this tutorial. Just download the Meteor binary! Yay!!
  • mrt is no longer used with Meteor 1.0

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)
  5. Edit the Vagrantfile with your preferred editor and add those four 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
  1. vagrant up (It will download box, configure meteor and get it up)
  2. 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:

  1. cd /vagrant (This is by default shared with the host)
  2. mrt create ~/meteorapp
  3. mrt create meteorapp && cd meteorapp && rm -rf .meteor && mkdir .meteor/ (Check your Windows folder you’ve created. It will be there!)
  4. Input these lines:
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
  1. 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. There's a project that does it automatically in win.meteor.com

Hope you like it,

Gabriel Pugliese

@gabrielsapo

@beshur

This comment has been minimized.

Copy link

@beshur beshur commented Aug 5, 2013

seems quite strange than upon every start vagrant re-downloading much of stuff

@mathphreak

This comment has been minimized.

Copy link

@mathphreak mathphreak commented Aug 9, 2013

@beshur: Vagrant seems to rerun meteor.sh every time you run vagrant up. I wrapped my entire meteor.sh in a if [ ! -d ~/meteorapp ] to keep this from happening.

@gabrielhpugliese

This comment has been minimized.

Copy link
Owner Author

@gabrielhpugliese gabrielhpugliese commented Sep 13, 2013

Yeah and I've put on Hints bullets:

"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."

@ChaoticNeutralCode

This comment has been minimized.

Copy link

@ChaoticNeutralCode ChaoticNeutralCode commented Jan 5, 2014

The download URL for Vagrant has actually changed. That site directs you to http://www.vagrantup.com/downloads.html.

@alnafie

This comment has been minimized.

Copy link

@alnafie alnafie commented Jan 7, 2014

This provisioning script is in need of some serious updating. It installs node v.0.8.23. And as far as I know, you no longer need to install mongodb. meteor should handle that for you.

@s-trooper

This comment has been minimized.

Copy link

@s-trooper s-trooper commented Jan 20, 2014

don't work on win7 x64

@WimAtIHomer

This comment has been minimized.

Copy link

@WimAtIHomer WimAtIHomer commented Feb 14, 2014

to make it work with packages, I also had to mount the packages dir.

cd /home/vagrant/meteorapp
mkdir packages
sudo mount --bind /home/vagrant/meteorapp/packages/ /vagrant/meteorapp/packages/
echo “sudo mount --bind /home/vagrant/meteorapp/packages/ /vagrant/meteorapp/packages/” >> ~/.bashrc && source ~/.bashrc
@c316

This comment has been minimized.

Copy link

@c316 c316 commented Apr 29, 2014

mrt add command can't be run from /vagrant/appname directory. Is that normal? Also, the files don't seem to be syncing to the desktop or back from it to the vagrant machine.

Here is the error I get when I try to run mrt commands from /vagrant/appname

♥vagrant@precise32:/vagrant/todos$ mrt add spin
√ spin
    tag: https://github.com/SachaG/meteor-spin.git#v0.2.2

fs.js:730
  return binding.symlink(preprocessSymlinkDestination(destination, type),
                 ^
Error: UNKNOWN, unknown error '/vagrant/todos/packages/spin'
    at Object.fs.symlinkSync (fs.js:730:18)
    at /usr/local/lib/node_modules/meteorite/lib/dependencies/package.js:129:10
    at /usr/local/lib/node_modules/meteorite/lib/sources/git.js:84:15
    at GitSource._load (/usr/local/lib/node_modules/meteorite/lib/sources/git.js
:141:12)
    at /usr/local/lib/node_modules/meteorite/lib/sources/git.js:82:18
    at /usr/local/lib/node_modules/meteorite/lib/sources/git.js:98:5
    at /usr/local/lib/node_modules/meteorite/lib/sources/git.js:263:5
    at ChildProcess.exithandler (child_process.js:635:7)
    at ChildProcess.EventEmitter.emit (events.js:117:20)
    at maybeClose (child_process.js:743:16)
vagrant@precise32:/vagrant/todos$
@c316

This comment has been minimized.

Copy link

@c316 c316 commented Apr 29, 2014

Also, I've updated the meteor.sh file with the latest node version below.

#!/bin/bash
sudo apt-get update
sudo apt-get install python-software-properties
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | sudo tee -a /etc/apt/sources.list.d/10gen.list
sudo apt-get update
sudo apt-get install -y git mongodb-10gen curl
cd /usr/local
wget http://nodejs.org/dist/v0.10.11/node-v0.10.11-linux-x86.tar.gz
sudo tar -xvzf node-v0.10.11-linux-x86.tar.gz --strip=1
rm -f node-v0.10.11-linux-x86.tar.gz
curl https://install.meteor.com | sudo sh
sudo npm install -g meteorite
@c316

This comment has been minimized.

Copy link

@c316 c316 commented Apr 29, 2014

Here is what I had to do in order to get around the above error.

First do a normal mrt add iron-router (or whatever package you are adding)
You'll still get the above error.

√ iron-router
    tag: https://github.com/EventedMind/iron-router.git#v0.7.1

Now use the git path that is listed when meteorite tries to install, but without the version number. (for the above package it is https://github.com/EventedMind/iron-router.git)

cd packages/
git clone https://github.com/EventedMind/iron-router.git iron-router

If there are any dependencies you'll have to manually git them as well (I know, not cool).

cd ..
mrt

√ blaze-layout
    tag: https://github.com/EventedMind/blaze-layout.git#v0.2.4

If there are dependencies you'll see the same git path, do the same

cd pakcages/
git clone https://github.com/EventedMind/blaze-layout.git blaze-layout

Now you should be able to run mrt, you'll notice that meteorite sees that you manually installed the packages so it skips installing them.

@hamxiaoz

This comment has been minimized.

Copy link

@hamxiaoz hamxiaoz commented May 6, 2014

@c316 I just use sudo mrt add spin and it worked

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented May 11, 2014

I've created a Vagrant configuration that fixes the problems I encountered and is up to date. I recommend to use it as a starting point: https://github.com/Sanjo/vagrant-meteor

@jhgaylor

This comment has been minimized.

Copy link

@jhgaylor jhgaylor commented May 23, 2014

@sanjo your solution helped me out. 👍

@omarjebari

This comment has been minimized.

Copy link

@omarjebari omarjebari commented Jul 18, 2014

I have followed your instructions but i dont know where i should perform the >mrt run
I can edit files in my window share and they modify the files at /vagrant/myapp but they dont change the files in /home/vagrant/myapp.
If i run meteor from /home/vagrant/myapp then the app works but it doesnt pick up any of the file changes i make from windows.
Can you make the instructions clearer please?

@gabrielhpugliese

This comment has been minimized.

Copy link
Owner Author

@gabrielhpugliese gabrielhpugliese commented Aug 1, 2014

You should run mrt run inside the vagrant window and inside the project root you've created

@omarjebari

This comment has been minimized.

Copy link

@omarjebari omarjebari commented Aug 6, 2014

So just to clarify, in vagrant i should run:

mrt run
inside /vagrant/myapp AND /home/vagrant/myapp?

@YordanGeorgiev

This comment has been minimized.

Copy link

@YordanGeorgiev YordanGeorgiev commented Aug 14, 2014

Just a note asite ...
This line copy pasted from chrome on windows ... translates into some nasty backticks not proper quotes ...

echo "sudo mount --bind /home/vagrant/meteorapp/.meteor/ /vagrant/meteorapp/.meteor/" >> ~/.bashrc && source ~/.bashrc

  • Did not quite understand the Windows cmd path part but having cyginwin + vagrant + the configuratoin entries was enough for me ...
    VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "hashicorp/precise32"
config.vm.synced_folder '/var/', '/vagrant'
config.vm.network :forwarded_port, host: 13306, guest: 13306
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
end

@JimKitzmiller

This comment has been minimized.

Copy link

@JimKitzmiller JimKitzmiller commented Sep 1, 2014

Thank you for providing this info. Are there plans to update this to to allow for Meteor 0.9?

@corentin-branquet

This comment has been minimized.

Copy link

@corentin-branquet corentin-branquet commented Sep 9, 2014

Great tutorial, it works perfectly !

@donovansolms

This comment has been minimized.

Copy link

@donovansolms donovansolms commented Oct 8, 2014

Awesome tutorial, thanks!

@dotnetwise

This comment has been minimized.

Copy link

@dotnetwise dotnetwise commented Oct 9, 2014

I have made it to use precise64

  config.vm.box = "precise64"

Also NFS performs better performance

# Required for NFS to work, pick any local IP
config.vm.network :private_network, ip: '192.168.50.50'
#Use NFS for shared folders for better performance
config.vm.synced_folder '.', '/vagrant', nfs: true

And finally allocated more than 1 cpu:

 # Give VM 1/4 system memory & access to all cpu cores on the host
  if host =~ /darwin/
    cpus = `sysctl -n hw.ncpu`.to_i
    # sysctl returns Bytes and we need to convert to MB
    mem = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 4
  elsif host =~ /linux/
    cpus = `nproc`.to_i
    # meminfo shows KB and we need to convert to MB
    mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 / 4
  else # sorry Windows folks, I can't help you
    cpus = 2
    mem = 768
  end
config.vm.provider "virtualbox" do |vb|
  vb.customize ["modifyvm", :id, "--memory", mem]
  vb.customize ["modifyvm", :id, "--cpus", cpus]
#....
end
@mfrimu

This comment has been minimized.

Copy link

@mfrimu mfrimu commented Oct 26, 2014

VirtualBox no longer working on 'some' random windows installs since a few months... Way to go Oracle !

@ahoereth

This comment has been minimized.

Copy link

@ahoereth ahoereth commented Oct 29, 2014

I created a fork of this gist and updated it to work with Meteor 1.0.

  • Vagrant 1.6.5
  • No more mrt
  • Ubuntu 14.04
@dandv

This comment has been minimized.

Copy link

@dandv dandv commented Nov 24, 2014

Please note the first official Windows preview from MDG.

@gabrielhpugliese

This comment has been minimized.

Copy link
Owner Author

@gabrielhpugliese gabrielhpugliese commented Nov 28, 2014

Thanks for all optimizations guys. Added the official windows preview link to the gist!

@glasser

This comment has been minimized.

Copy link

@glasser glasser commented Dec 19, 2014

@gabrielhpugliese: As of Meteor 1.0.2, setting the METEOR_WATCH_FORCE_POLLING environment variable is recommended for users of shared filesystems like Vagrant/Virtualbox's vboxsf which do not support efficient change notification events. (Without this env var it will still work but will only check for changes every 5 seconds.) Maybe you can update the tutorial to tell users to set this (and explain how to set it)?

@gabrieljenik

This comment has been minimized.

Copy link

@gabrieljenik gabrieljenik commented Dec 24, 2014

@servatj

This comment has been minimized.

Copy link

@servatj servatj commented Jan 24, 2015

Thank you very much , very usefull for me ;)

@athergeek

This comment has been minimized.

Copy link

@athergeek athergeek commented Feb 1, 2015

Excellent tutorial. Just finished installing everything successfully on Windows 8.1 Pro. After that i started reading thread posts and noticed there are updated forks / versions of the same process avaialble now. The question is Do i need to update my node from v0.8.23 to the latest version which is v0.10.36 ? if yes then what is the best way to do it ? Does Meteor preview for windows supports iron router and all other stuff ? https://github.com/meteor/meteor/wiki/Preview-of-Meteor-on-Windows

@jmar42

This comment has been minimized.

Copy link

@jmar42 jmar42 commented Feb 17, 2015

Are there any easier instructions on installing this with Vagrant?? I'm stuck on # 3-5 and #1-2 on the "Steps on Windows command-line:" Is there a reason for "Steps on Ubuntu command-line::" instructions?

@powpow12

This comment has been minimized.

Copy link

@powpow12 powpow12 commented Feb 27, 2015

anyone else having issues with running mrt? I receive an error message saying command doesn't exist.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Feb 27, 2015

@powpow12: mrt doesn't exists anymore and is replaced with the 'meteor' command :)

@powpow12

This comment has been minimized.

Copy link

@powpow12 powpow12 commented Mar 1, 2015

excellent, I actually was about to track this down on my own. Now my only outstanding issue is I have the vagrant server running on localhost:3000 but I can't pull it up on my windows browser. I was able to confirm the server is working by opening up another instance and using the curl command. Any help would be appreciated.

@ivanbulanov

This comment has been minimized.

Copy link

@ivanbulanov ivanbulanov commented Mar 5, 2015

Here is a way to perform version control on the host. Instead of moving .meteor and then mounting it at the original place all we need is to make symbolic links work and specify a non-default MongoDB location.

Warning VirtualBox doesn't support symlinks for security reasons. The following solution may impose even greater risk because of the use of the administrator privilege.

Based on this discussion here is how to do it:

  • Run Windows command shell as administrator
  • Execute in the shell fsutil behavior set SymlinkEvaluation L2L:1 R2R:1 L2R:1 R2L:1
  • Edit your Vagrantfile and include
  config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/meteor", "1"]
  end
  • Run vagrant as administrator. You can start it from the same shell as you were using for the first couple of steps or start another one.
  • meteor create your project in the shared directory.
  • Install MongoDB on the guest.
  • Execute export MONGO_URL=mongodb://localhost:27017/your_db_name
  • Update meteor to the WINDOWS_PREVIEW release: meteor update --release WINDOWS-PREVIEW@0.2.0 Otherwise the app wont' rebuild after the source code changes. The version has better support for windows file system quirks. However, it may not support some other functionality.
  • cd to the app directory, run meteor and enjoy.
@chevdor

This comment has been minimized.

Copy link

@chevdor chevdor commented Mar 13, 2015

I had to tweak a bit the meteor.js script to get the gpg key from the ubuntu server:

#!/bin/bash
sudo apt-get update
sudo apt-get install python-software-properties
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | sudo tee -a /etc/apt/sources.list.d/10gen.list
sudo apt-get update
sudo apt-get install -y git mongodb-10gen curl
cd /usr/local
sudo wget http://nodejs.org/dist/v0.10.11/node-v0.10.11-linux-x86.tar.gz
sudo tar -xvzf node-v0.10.11-linux-x86.tar.gz --strip=1
sudo rm -f node-v0.10.11-linux-x86.tar.gz
curl https://install.meteor.com | sudo sh
sudo npm install -g meteorite
@gabrielpugliese-luizalabs

This comment has been minimized.

Copy link

@gabrielpugliese-luizalabs gabrielpugliese-luizalabs commented May 12, 2015

I have updated the "Before you continue" section. Meteor has a installer for Windows now!

@kodybrown

This comment has been minimized.

Copy link

@kodybrown kodybrown commented Jul 31, 2015

Thanks for the tutorial. I installed the Windows version. But, the Windows version of Meteor does not allow calling meteor run android-device.. I checked into port forwarding and it is doable, although may present some headaches. Anyway, I am wondering if anyone has gotten the Vagrant method working and with running / connecting to an Android device.

@dstollie

This comment has been minimized.

Copy link

@dstollie dstollie commented Aug 3, 2015

Just wanted to use vagrant on my windows machine, tried the vagrant file above and saw it was some kind of outdated so I changed it to something more up-to-date and noob friendly:

#!/bin/bash

sudo apt-get update

#1. Install git and curl
sudo apt-get install -y git curl
#2. Update the os
sudo apt-get update
#3. Go to the local user directory
cd /usr/local
#4. Download NodeJS
sudo wget http://nodejs.org/dist/v0.10.11/node-v0.10.11-linux-x86.tar.gz
#5. Unpack and install NodeJS
sudo tar -xvzf node-v0.10.11-linux-x86.tar.gz --strip=1
#6. Remove the tar.gz file
rm -f node-v0.10.11-linux-x86.tar.gz
#7. And last but not least, install meteor itself
curl https://install.meteor.com | sudo sh
#8. Oh yeah, run the meteor help command to let meteor do soem startup stuff
meteor --help
@forgetso

This comment has been minimized.

Copy link

@forgetso forgetso commented Apr 12, 2016

Thanks a lot for the symlink tip!

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