'Truffle Installation Error in "nodejs version 8.10.0" npm version "3.5.2"

I have been trying to install truffle in my Ubuntu 18.04 machine with nodejs version 8.10.0 and npm version 3.5.2, but it shows the error as below.

loadDep:original-require  | |#######################----------------------------------------------------------------------------------------|
loadDep:fsevents -> 304   | |##############################---------------------------------------------------------------------------------|
npm ERR! Linux 5.3.0-26-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "truffle"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! code EMISSINGARG

npm ERR! typeerror Error: Missing required argument #1
npm ERR! typeerror     at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3)
npm ERR! typeerror     at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
npm ERR! typeerror     at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12)
npm ERR! typeerror     at /usr/share/npm/lib/install/deps.js:457:7
npm ERR! typeerror     at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror     at /usr/share/npm/lib/fetch-package-metadata.js:37:12
npm ERR! typeerror     at addRequestedAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:82:5)
npm ERR! typeerror     at returnAndAddMetadata (/usr/share/npm/lib/fetch-package-metadata.js:117:7)
npm ERR! typeerror     at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20)
npm ERR! typeerror     at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror     <http://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /home/lenovo/npm-debug.log

How do I resolve this?



Solution 1:[1]

The problem is happening because of an incompatibility issue encountered between node v8.10.0 and npm v3.5.2 which are same the versions currently found in Ubuntu 18.04's official repository at the current time of writing.

To fix the issue you need to update both Node.js and npm to the latest version by the following two commands as listed by user eezoo in the corresponding Github's npm issue:

  1. Update nodejs to the latest version

sudo npm install -g n
sudo n latest

  1. Update npm to the latest version

sudo npm install -g npm

  1. After the updates, while installing truffle you should also encounter the following error: permission denied, open '/root/.config/truffle/config.json. To fix this, install truffle with the --unsafe-perm flag set as true:

sudo npm install -g truffle --unsafe-perm=true

  1. To uninstall the latest nodejs and npm binaries you can remove them from /usr/local/bin.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 brandbir