I am working with webpack and I need to execute ./node_modules/webpack/bin/webpack.js
using npx
. npx webpack
would run the webpack binary (./node_modules/webpack/bin/webpack
), but each time I execute npx webpack I get
bash: npx: command not found
.
I am using:
node: v9.5.0
npm: 5.6.0
nvm: 1.1.5
webpack: 3.11.0
npx should come with npm 5.2+, and you have node 5.6 .. I found that when I install node using nvm for Windows, it doesn't download npx. so just install npx globally:
npm i -g npx
In Linux or Mac OS, if you found any permission related errors use sudo before it.
sudo npm i -g npx
check versions of node, npm, npx as given below. if npx is not installed then use npm i -g npx
node -v
npm -v
npx -v
if you are using Linux system, use sudo
command
sudo npm i -g npx
Uninlstallation
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
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.
I returned to a system after a while, and even though it had Node 12.x, there was no npx
or even npm
available. I had installed Node via nvm
, so I removed it, reinstalled it and then installed the latest Node LTS. This got me both npm
and npx
.
Updating node helped me, whether that be from the command line or just re-downloading it from the web
try :
sudo su
then
npm i npx
or
npi i -g npx
check your npx version by
npx -v
Source: Stackoverflow.com