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
$ n --version
6.7.0
$ command -v node
/Users/tekumara/.n/bin/node
$ node -p process.platform
darwin
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.
Most helpful comment
ndoes 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
npmout of the install. Try--preserveor-p.