After some years running this just fine, I think I can confidently say there are no real issues (at least, I didn't run into them). The only issue is getting n
to work. For that, read below.
Solving it with npm n
I'm installing it as a user with sudo access and I don't ever want to sudo
npm or node to make it work (why?).
Install npm: sudo apt install npm
.
Set prefix for npm : npm config set prefix ~/.npm
Upgrade npm to the latest version, npm i -g npm
.
(Update: apt's npm is now so old that you should get an error message when trying to update, because the bundled node version is too old. In this case, run this command again at the end of all these instructions)
- Set environmental variables in
~/.profile
file (these changes will only work after you log out and log in again, or if you run source ~/.profile
):
# vars to avoid ever using sudo for npm
export PATH="$PATH:$HOME/.npm/bin"
# these are for n and where it'll install nodejs:
export N_PREFIX=$HOME/.n
export PATH="$PATH:$N_PREFIX/bin"
You might also want to add these lines to ~/.bash_profile
, ~/.bash_login
or ~/.bashrc
in case you need to source ~/.profile
every time you open a new terminal for npm, node and n to be recognized. See this for the reason.
Run source ~/.profile
to update the environmental variables. This way bash will find the path to npm
and n
during this session (i.e., without having to log out and then log in again).
Use npm n
package to upgrade node (see: https://askubuntu.com/a/663052/808646):
# Intructions: https://www.npmjs.com/package/n
# Some people also suggest npm cache clean -f, but (I think) this isn't necessary here.
# I'm using lts for the stable release, for the latest use instead: n latest
npm install -g n
n lts
- Uninstall the previous nodejs that came installed by npm:
sudo apt-get purge nodejs
.
Explanation: this step is crucial. So far, this is what happened: you installed npm
, but it actually installed old nodejs
and old npm
on top of it. Although you purportedly "installed" a new nodejs
using n
, the previous nodejs
takes precedence and n
can't really install the new nodejs
it downloaded, you must first remove the old one.
However, if you remove it without installing a new npm
, you will not have npm
anymore, because uninstalling old nodejs
uninstalls old npm
too (I think... or can it work if you just export all vars again? Maybe just having n
installed with a nodejs/npm version will be enough?). Therefore, you must install a new npm
(you did that in step 3) and a new nodejs
using n
(you did that in step 6) before uninstalling old nodejs
. The reason why you also need a new nodejs
install is that without a new nodejs
, new npm
won't run, it requires a current nodejs
install.
- Check if it worked. If it didn't, try logging out and logging in again or enter
n
and select the correct nodejs version (*by default, it'll use the npm that's bundled with that nodejs version, but there are options to prevent this): node -v
n
are: 1) it's a module of npm, not a bash script etc.; 2) it's actually very easy to use; 3) from what I saw in regard to nvm, setup seems a bit less convoluted. But I'm facing a problem: active node version points to/usr/bin/node
, but I want it to point to my custom folder, where node v14 is installed~/.n/bin/node
. Lost some hours but I still don't know what to do here. I tried usingn
and selecting v14 (pressing Enter "to install"), but the active version isn't updated (i.e., v14 isn't installed?)PATH
were appended to the end of it, runningnode
would always get me the old version 10 of node. I've updated my question to include all the steps to install it via npm nn
. But the original question was whether there could be disadvantages. I'll move the steps into an answer, saying I never had issues, to make the question cleaner