How can I uninstall or upgrade my old node.js version?

1 Minute Solution Without using sudo:

The current stable "LTS" version of node is 12.18.4 (2020-10-03) see: nodejs.org for latest.

Step 1 - Get NVM (Node Version Manger)

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

If you're curious about the installation command read the source code
... its been reviewed by several node.js security experts

Step 2 - Install the version of node.js you need

Once you've got NVM you can install a specific version of Node.js using the nvm command:

nvm install v12.18.4

Note: you may need to close & re-open your terminal window for nvm command to be available.

You should expect to see something like this in your terminal:

Now using node v12.18.4

Step 3 - Enjoy the rest of your day!

Yes, it's that easy and didn't require sudo!
Now please Upvote this (so others can avoid sudo-installing things!)
and have a lovely day writing node.js code!

Microsoft Windows User? Use: https://github.com/coreybutler/nvm-windows

 tl;dr

Review of the node mailing list indicates that using NVM (Node Version Manager) is the preferred way to manage your nodejs versioning/upgrading. see: github.com/nvm-sh/nvm

NVM is considered "better" than N because the verbose commands mean is much easier to keep track of what you are doing in your Terminal/SSH Log. Its also faster, saves kittens by not requiring sudo and is used by the team at NPM the node.js security experts!


  1. Install npm using curl (or wget)
    curl http://npmjs.org/install.sh | sh
  2. Install n using npm
    npm install -g n
  3. Install the latest version of node using n
    n latest

n is a node version manager. It does all the work for you. It installs and switches to the version you specify, or just switches if you already have it installed.

Note: If you're having trouble installing stuff due to permissions, don't use sudo. Enter this command once to set your user account as the owner of the /usr/local/ directory, so that you can just issue normal commands in there without sudo. It's a more sane alternative.

sudo chown -R $USER /usr/local

Do the exact same thing again. The new binary will be copied over the old one.

  • git clone creates a copy of git repository node's source code is in
  • cd node/ changes directory to the one you just created with those files
  • ./configure checks for dependencies and creates a makefile
  • make executes that makefile, which results in compiling the source code into binary executable(s), libraries and any other outputs
  • ls -l lists the files in the current directory
  • node runs the node binary executable you just compiled from source, to ensure the compilation was successful
  • sudo make install copies the files you just created from the current directory to their permanent homes, /usr/local/bin and such

The last step overwrites whatever's already there with what you just built.

Tags:

Linux

Node.Js