upgrade or update nodejs
Open a terminal window.
Run the following command to update npm (Node Package Manager) to the latest version:
npm install -g npm
Check the currently installed version of Node.js by using the following command:
node -v
If you have Node.js version manager (nvm) installed, you can use it to upgrade Node.js. Otherwise, you can update Node.js directly with the following commands:
npm cache clean -f npm install -g n n stable
Verify the updated Node.js version by running:
node -v
If you encounter permission issues during the update, you may need to use sudo:
sudo npm install -g n sudo n stable
Confirm the updated Node.js version once again:
node -v
Restart your terminal to apply the changes.