Created
November 15, 2015 23:05
-
-
Save lynxtdc/ae6f0c52d4c515ebbba8 to your computer and use it in GitHub Desktop.
Getting Node running on Windows with Homestead
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I did a fair amount of poking around with this issue and found the following combination of suggestions to work for me. | |
I am running Windows 7 Professional 64 bit, Homestead 2.0 and install all my projects in a "code/project name" directory | |
Seems the main reason for NPM not working on Windows machines is it runs up against the file name character limit in Windows even though | |
you are installing on your vagrant/homestead box. | |
First I added this to my homestead.rb file: | |
config.vm.provider "virtualbox" do |vb| vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"] | |
as follows: | |
# Configure A Few VirtualBox Settings | |
config.vm.provider "virtualbox" do |vb| | |
vb.name = settings["name"] ||= "homestead" | |
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"] | |
vb.customize ["modifyvm", :id, "--memory", settings["memory"] ||= "2048"] | |
vb.customize ["modifyvm", :id, "--cpus", settings["cpus"] ||= "1"] | |
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"] | |
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] | |
vb.customize ["modifyvm", :id, "--ostype", "Ubuntu_64"] | |
end | |
Then I added the following to my .bash_aliases file in /home/vagrant (you may need to adjust paths to get it to work on your setup) | |
donpm() | |
{ | |
SITE=${1:-"default"} | |
if [ ! -d "/usr/local/npm/$SITE" ]; then | |
sudo mkdir -p /usr/local/npm/$SITE | |
fi | |
if [ ! -f "/usr/local/npm/$SITE/package.json" ]; then | |
sudo cp -f ~/code/$SITE/package.json /usr/local/npm/$SITE/ | |
fi | |
cd /usr/local/npm/$SITE | |
sudo npm install | |
if [ ! -L "~/code/$SITE/node_modules" ]; then | |
sudo ln -s /usr/local/npm/$SITE/node_modules ~/code/$SITE/node_modules | |
fi | |
cd ~/code/$SITE | |
} | |
and added this at the end of the file | |
alias winpm=donpm | |
NOTE: the last bit of the script (the sym-linking part) does not work on my computer...but that's probably my computer. So I run that manually afterwards | |
With the above in place I do the following to get node installed for a project: | |
I SSH into vagrant and from the root (may be from "code" directory) run winpm <name of project directory> | |
(this process take a while to complete) | |
When finished | |
close vagrant shell | |
halt the vagrant box | |
close GIT Bash (the CLI tool I am using) | |
Restart GIT Bash as administrator | |
vagrant up | |
SSH into vagrant | |
run the sym linking command: | |
sudo ln -s /usr/local/npm/<name of project directory>/node_modules ~/code/<name of project directory>/node_modules | |
After you're finished you should be able to back out of everything, restart vagrant as you normally would and have Node/npm accessible | |
from your project. | |
The only other issue I've noticed, and again is probably due to my machine, is Gulp Notify does not work...but running gulp from | |
your project via SSH will do everything else it's supposed to. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment