Skip to content

Instantly share code, notes, and snippets.

@airbugg
Last active July 21, 2017 07:06
Show Gist options
  • Save airbugg/ceb82dfc037979a0ce94224b95aa16c6 to your computer and use it in GitHub Desktop.
Save airbugg/ceb82dfc037979a0ce94224b95aa16c6 to your computer and use it in GitHub Desktop.
`n` - a faster `nvm`, and how to get there

Rationale

It takes over 1000ms to switch node versions (using avn) whenever we dir into a project folder. Makes carpe diem harder. Degrades my chi. Makes me wanna hurt babies.

Sold! How?

Strictly speaking, you can uninstall nvm (which I'm assuming you use)

rm -rf $NVM_DIR

and the just install n from npm:

npm i -g n

But that's just being lazy, and n is known to break npm and shit. There's a better way.

Spring cleaning

Quickly, off the top of your head (and without running which node) - where do you keep all your node versions? Never mind that, where's the current node version installed? How did it get there; did you use brew install node, or downloaded the installer from the official site? Maybe it was already there when you got your computer. Thing is, if you don't know where your node lives, how do you expect to manage multiple versions of it, including all the different npms, efficiently?

I say, let's begin from scratch.

Go here. Follow the instructions to clear your system of all node related things. Oh, but first, run

npm list -g --depth=0

So you'll know which global packages you need to reinstall later.

If you use brew, I suggest running brew uninstall node && brew prune before hand.

Installing node + n using n-install

Two reasons for using n-install:

  1. It doesn't require sudo.
  2. It doesn't require sudo.

Cool.

curl -L https://git.io/n-install | bash

Now, install avn-n for that sweet automatic package-switching magic:

npm i -g avn-n

Now, go visit a folder with an .nvmrc file in it. Go on. See how fast it is. Totally worth it.

Repopulate

Time to reinstall all those global node modules. Pesky, I know. On the flip side, now you know where everything lives and how it got there. And your avn is so much faster now.

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