Skip to content

Instantly share code, notes, and snippets.

Last active May 29, 2019 03:51
What would you like to do?
Using node.js / npm with PortableGit


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!


(1) Download the latest version of PortableGit:

And follow the instructions below to actually make PortableGit save files in a portable location.

(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: (If you're using 32-bit, switch the URL to win-x86)

Download 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:

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 -

Create a file called .bashrc in your home/portable folder.

In it, put the following:

# function to easily add a path
pathadd() {
  if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then

# 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!

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