A, install,

sudo apt-get install nodejs

sudo apt-get install npm

Second, the upgrade

sudo npm install -g n

Sudo n stable # update node.js to latest stable version

node -v

npm -v

N is a Node toolkit that provides several upgrade command parameters:

N Latest Installation Latest version Node n stable Installing the latest stable version Node N LTS Installing the latest long-term maintenance (LTS)Node n version Installs a Node based on the provided versionCopy the code

Three, output,

~ $sudo n stable installing: node - v12.16.1 mkdir: / usr/local/n/versions/node / 12.16.1 fetch: https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz installed: v12.16.1 (with NPM 6.13.4) Note: the node command changed location and the old location may be remembered in your current shell. old : /usr/bin/node new : /usr/local/bin/node To reset the command location hash either start a new shell, or execute PATH="$PATH"Copy the code

Prompt to restart terminal or execute PATH=”$PATH”

Four, unloading

sudo npm uninstall npm -g

sudo apt-get remove nodejs

Or:

Uninstall NodeJS from Ubuntu and run sudo apt-get remove NodeJS to remove the package but keep the configuration file.

To delete packages and configuration files, run sudo apt-get purge nodejs

Finally, you can run the following command toremove all unused files and free disk space sudo apt-get autoremove