Switch between Node.js versions easily

Quickly downgrade or upgrade your Node.js version

Skip right to the solution

I encountered a really annoying problem last week while doing a small project for an agency that required downgrading Node.js.

I downloaded the WordPress theme, noted they are using gulp, popped open the command line (I’ve recently switched to Hyper.js and really enjoying it) and typed in npm install as one does.

It wouldn’t work. It kept failing. First I thought the version of SASS was the problem (that’s where the installation would hang up), then I thought I could just update everything and hopefully it would work.

Nope. Turns out Gulp 3 is incompatible with the latest version of Node.js (at the time of writing that is 12.16.2. I eventually figured this out after combing Stack Overflow (really, what would we do without Stack Overflow?).

I went through a bunch of options (including rewriting their gulpfile in Gulp 4 syntax..) but eventually I resigned myself: I’d have to downgrade Node.js on my machine to make life easier. That’s when I discovered n.

Life. Saver.

n let’s you switch between Node.js versions on your machine in the blink of an eye. Installation is simple. In your command line tool key in:

npm install -g n

Then you can install any number of Node.js versions to switch between. To be safe, I installed v10.16.0:

n 10.16.0

And made sure I also have the latest version available, of course:

n lts

To switch between the two, you type in n, hit Enter, use the up/down arrow keys to choose a Node.js version, hit Enter again, and voila! You just changed the Node.js version on your machine!

Not yet sure how nicely this plays with brew, I originally installed Node.js with Homebrew (as one does) but I’m not super concerned. Edit: Looks like this plays just fine with Homebrew!

I hope that helped you with whichever node app you were trying to get working!

I write helpful tutorials for developers. Get more helpful tutorials straight in your inbox: