Contents
  1. Problem Description
  2. Solution
  3. Uninstall Node.js
  4. Install Node.js

Problem Description

Node.js was not installed correctly: after installation, node -v produced output, but npm -v did not respond.

Reinstall Node.js

Solution

Uninstall Node.js

sudo apt-get remove nodejs
sudo apt-get remove --purge npm
sudo apt-get remove --purge nodejs

Go to /usr/local/lib and delete all node and node_modules folders. Go to /usr/local/include and delete all node and node_modules folders. (In my case, I deleted the nodejs folder.)

Install Node.js

sudo apt-get install nodejs
node -v

# 安装最新的 node v10.x
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
npm -v