Skip to content

Instantly share code, notes, and snippets.

@glenjamin
Last active September 20, 2015 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glenjamin/919224bde54d7a6daf3a to your computer and use it in GitHub Desktop.
Save glenjamin/919224bde54d7a6daf3a to your computer and use it in GitHub Desktop.
Standalone npm

Standalone npm

When using tools like n or nvm it's often a bit annoying to have the npm version continually reset to whichever was bundled with the release being switched to.

Here's an alternative: having an npm installed separately.

This is especially useful if you want to try out npm@3 neatly.

sudo mkdir /opt/npm3
sudo chown $USER: /opt/npm3
npm install --global --prefix=/opt/npm3 npm@3
npm -v
/opt/npm3/bin/npm -v 

This will install npm into /opt/npm3, and make it accessible as long as you add /opt/npm/bin3 to your path.

You can do this with whichever directories you want to create more versions.

Switching

npm3() {
    if [ "$1" = "off" ]; then
        echo "Removing npm3 from path"
        export PATH=`echo $PATH | sed 's/\/opt\/npm3\/bin://g'`
        return
    fi
    echo "Adding npm3 to path"
    export PATH=/opt/npm3/bin:$PATH
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment