Prologue
I develop on Windows (yeah, I hear your jeers, linux users!), so to use Git, I use Git for Windows.
However, I use Git for Windows (portable version) so I can keep my dev environment centrally located. This is so I can reuse this environment simply by copying my PortableGit directory to a USB drive.
Using a portable set up means you can't use those handy automatic installers to your dev environment. This makes installing other scripts like node.js a little bit more difficult because you have to manually do-it-yourself. No biggie! This is what this guide is for!
Installation
(1) Download the latest version of PortableGit:
https://github.com/git-for-windows/git/releases/
And follow the instructions below to actually make PortableGit save files in a portable location.
https://gist.github.com/r-a-y/da6c3b1b99aafcb3e97e311280aa9434
(2) Installing node.js and npm
Now that you have PortableGit set up, you should have a folder called home/portable
in the folder where you extracted PortableGit.
Download the node.js Windows binary:
https://nodejs.org/dist/latest/win-x64/node.exe
(If you're using 32-bit, switch the URL to win-x86
)
Download npm:
http://nodejs.org/dist/npm/
You should copy the files to home/portable/node
.
Bash users have to do one additional step for npm to work correctly. Copy the /home/portable/node/node_modules/npm/bin/npm
file to the /home/portable/node/
directory.
This will allow you to run npm in bash.
(3) Upgrade npm
The npm version listed in step 2 is quite old. Upgrading npm is a little complicated for Windows users, but fortunately Microsoft provided an easy way to upgrade npm:
https://github.com/felixrieseberg/npm-windows-upgrade
You'll want to install their npm-windows-upgrade
package, but do not run the command yet.
Instead, run this:
npm-windows-upgrade --npm-path "C:\PATH\home\portable\node"
Change C:\PATH\home\portable\node
to the absolute path where we installed node in step 2.
(4) Adding node.js to your PATH (for bash users)
Now that you've installed node.js and npm, you still need to let msysgit know about it so you can run node and npm.
Since I use the bundled version of bash that comes with PortableGit, this section is applicable only to bash users. Windows command-line users have to add the PATH using a method similar to this - https://gist.github.com/Anachron/7006751
Create a file called .bashrc
in your home/portable
folder.
In it, put the following:
# function to easily add a path
# http://superuser.com/a/39995
pathadd() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="${PATH:+"$PATH:"}$1"
fi
}
# add node directory to PATH
pathadd $HOME/node
Now, run git-bash.bat
as usual and type:
npm --version
You should get the npm version number and you should be up and running!