Remove NodeJs and npm in your system and reinstall it with the following commands:
Uninstallation
sudo apt remove nodejs
sudo apt remove npm
Fresh Installation
sudo apt install nodejs
sudo apt install npm
Configuration optional, in some cases users may face permission errors.
user defined directory where npm will install packages
mkdir ~/.npm-global
configure npm
npm config set prefix '~/.npm-global'
add directory to path
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.profile
refresh path for the current session
source ~/.profile
cross-check npm and node modules installed successfully in our system
node -v
npm -v
Installation of npx
sudo npm i -g npx
npx -v
Well done, we are ready to go. Now you can easily use npx
anywhere in your system.