
How to Install Node.js for Ubuntu 20.04 LTS? - iroleh
https://iroleh.me/how-to-install-nodejs-for-ubuntu-2004-lts-ck9fj390t069jcxs1aytehpt6
======
nailer
Replace '10' if you want another version:

curl -sL
[https://deb.nodesource.com/setup_10.x](https://deb.nodesource.com/setup_10.x)
| sudo -E bash -

sudo apt-get install -y nodejs

~~~
ronjouch
Better to point people at the official instructions, to give them context
about the thing you suggest them to sudocurl:
[https://github.com/nodesource/distributions#debinstall](https://github.com/nodesource/distributions#debinstall)
.

Installation nit aside, nodesource is my preferred way to upgrade node on
Debian/Ubuntu:

1\. It's "just a newer version" of the OS-packaged version! As simple/vanilla
as can be.

2\. No shell magic making it unclear whether programs running out of the shell
will pick up your nvm-managed version of node (most of the time, they won't)

3\. And if someday I need to try something on $OLDNODE, it's not much less
convenient than nvm: I can just download the deb for $OLDNODE and install it
anytime. Then, if you configure your apt cache to keep .debs in
/var/cache/apt, switching between versions like nvm does is a matter of just
running `sudo dpkg -i /var/cache/apt/node-whatever.deb`. (Sure, it's a bit
slower than nvm: a few seconds of install rather than milliseconds of updating
a symlink in nvm; still I prefer it for reasons 1. and 2.)

------
Waterluvian
Can I still just install NVM and use that to install and maintain Node? I
assume snap will suffer the same annoyances of apt where I can't trivially get
the exact version I want and switch among them.

~~~
wayneftw
If you don’t like NVM’s shell config shenanigans you can use n -
[https://github.com/tj/n](https://github.com/tj/n)

~~~
nicoburns
There'a also `nodenv` which I've taken to using recently. Doesn't slow down
opening new shells like nvm. And has a handy feature that will set the used
node version to whatever is found in a directory's `.node-version` file.

~~~
capableweb
You can also just wrap the nvm commands in a function. I have it named `n`, so
before doing any node/npm stuff in a shell, I run `n` then `node ....`
whatever I wanted. Simple and doesn't slow down opening new shells.

    
    
        function n() {
          export NVM_DIR="$HOME/.nvm"
          [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
          [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
        }
    

Found it to be a ok workaround for the issue. Otherwise I'm just on nvm just
because it continues to work and hasn't gotten in my way, since like 2013 or
something. If someone is in the same boat but wanna fix the "slow new shell"
thing, this is a quick fix for it.

Would love to hear what the "shell config shenanigans" wayneftw talked about,
haven't hit that myself.

------
pmontra
Is it possible to install multiple versions of node with snap, for multiple
projects of (possibly) multiple customers? That was not possible with apt.
I've been using nvm or asdf for ages because of that. Not only for node but
also for ruby (rvm or asdf), elixir (asdf), python (pyenv), php (asdf) and
probably something I'm forgetting about. I used docker for that sometimes but
mainly for databases (multiple PostgreSQLs and MySQLs.)

------
nicoburns
Note: Node 14 was released last week. You might want to use that rather than
13, as unlike 13 it will become an LTS supported release.

------
jlelse
I always do it like this:

sudo sh -c 'wget -qO- distro.tools/install/node | sh'

