Skip to content

Instantly share code, notes, and snippets.

@gabrielhpugliese
Last active April 19, 2022 14:37
Show Gist options
  • Save gabrielhpugliese/5855677 to your computer and use it in GitHub Desktop.
Save gabrielhpugliese/5855677 to your computer and use it in GitHub Desktop.
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

@hamxiaoz
Copy link

hamxiaoz commented May 6, 2014

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

Copy link

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
Copy link

@sanjo your solution helped me out. 👍

@omarjebari
Copy link

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
Copy link
Author

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

@omarjebari
Copy link

So just to clarify, in vagrant i should run:

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

@YordanGeorgiev
Copy link

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
Copy link

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

@corentin-branquet
Copy link

Great tutorial, it works perfectly !

@donovansolms
Copy link

Awesome tutorial, thanks!

@dotnetwise
Copy link

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
Copy link

mfrimu commented Oct 26, 2014

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

@ahoereth
Copy link

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
Copy link

dandv commented Nov 24, 2014

Please note the first official Windows preview from MDG.

@gabrielhpugliese
Copy link
Author

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

@glasser
Copy link

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
Copy link

@servatj
Copy link

servatj commented Jan 24, 2015

Thank you very much , very usefull for me ;)

@athergeek
Copy link

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
Copy link

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
Copy link

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

Copy link

ghost commented Feb 27, 2015

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

@powpow12
Copy link

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
Copy link

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 [email protected] 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
Copy link

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

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

@kodybrown
Copy link

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
Copy link

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
Copy link

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