N: Switch current node version quickly

Created on 6 Sep 2020  路  3Comments  路  Source: tj/n

Problem

I'd like to switch the current node version to an already downloaded version of node quickly (ie: ~100ms). It currently takes 3.5 - 7 secs.

$ time n 12
   installed : v12.18.3 (with npm 6.14.6)
n 12  0.26s user 1.36s system 45% cpu 3.597 total

Configuration Details

$ n --version
6.7.0

$ command -v node
/Users/tekumara/.n/bin/node

$ node -p process.platform
darwin

Most helpful comment

n does a full install, not just switching a symlink. That takes a while.

1) Do you have anti-virus on your Mac? I have seen some very slow installs (> 30 s) due to anti-virus when the file cache is cold. Try installing with anti-virus turned off to set a baseline.

2) There are far fewer files to copy if you leave npm out of the install. Try --preserve or -p.

$ time n 12
   installed : v12.18.3 (with npm 6.14.6)
n 12  0.30s user 1.99s system 44% cpu 5.141 total
$ time n 12
   installed : v12.18.3 (with npm 6.14.6)
n 12  0.28s user 1.60s system 58% cpu 3.222 total
$ time n --preserve 12
   installed : v12.18.3
n --preserve 12  0.27s user 0.46s system 39% cpu 1.835 total
$ time n --preserve 12
   installed : v12.18.3
n --preserve 12  0.24s user 0.22s system 30% cpu 1.519 total

All 3 comments

n does a full install, not just switching a symlink. That takes a while.

1) Do you have anti-virus on your Mac? I have seen some very slow installs (> 30 s) due to anti-virus when the file cache is cold. Try installing with anti-virus turned off to set a baseline.

2) There are far fewer files to copy if you leave npm out of the install. Try --preserve or -p.

$ time n 12
   installed : v12.18.3 (with npm 6.14.6)
n 12  0.30s user 1.99s system 44% cpu 5.141 total
$ time n 12
   installed : v12.18.3 (with npm 6.14.6)
n 12  0.28s user 1.60s system 58% cpu 3.222 total
$ time n --preserve 12
   installed : v12.18.3
n --preserve 12  0.27s user 0.46s system 39% cpu 1.835 total
$ time n --preserve 12
   installed : v12.18.3
n --preserve 12  0.24s user 0.22s system 30% cpu 1.519 total

Thanks for the explanation @shadowspawn. No I don't have anti-virus installed. --preserve is definitely faster, would be nice if it were the default. I'll try some of the alternative version managers and see if they are any quicker.

Thanks for closing with comment.

Some of the other managers switch versions by changing symlinks, or change PATH, or run a node shim to decide which node version to use. Different tradeoffs, but all faster than doing a full install so you should find a good alternative for a faster switch.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shadowspawn picture shadowspawn  路  8Comments

iarna picture iarna  路  3Comments

GeoffreyBooth picture GeoffreyBooth  路  8Comments

shadowspawn picture shadowspawn  路  6Comments

bo01ean picture bo01ean  路  4Comments