Upgrading node on WSL

Posted: 01 June, 2020 Category: recipes Tagged: wslnode

Ran into needing this when I switched to using the WSL shell halfway through a project and then realised that (of course!) it's an entirely different environment that I hadn't necessarily brought up to speed since installing ages ago.

> sudo apt-get purge nodejs

and now cleanup dependencies left behind:

> sudo apt-get autoremove

get rid of node source list:

> ls /etc/apt/sources.list.d
> sudo rm /etc/apt/sources.list.d/nodesource.list

now, "which node" should return nothing.

> which node
>

Now install node using the instructions here summarised as:

> sudo apt-get install curl
> curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash

CLOSE YOUR WSL TERMINAL and reopen first, then verify - these should work else re-attempt the curl ops. (nvm ls shoul return no nodes; we haven't installed it yet):

> command -v nvm
> nvm --version
> nvm ls

continue:

> nvm install node

verify installs (including npm, which u should also get with the install)

> node --version
> npm --version

Hereafter, whenever you cd into a project, you can do:

  • nvm ls-remote to see what versions of npm are available that you can install
  • nvm use [--lts | v0.0.0] to use latest stable or specific version