158

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

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
wokoro douye samuel
  • 2,194
  • 3
  • 15
  • 29

14 Answers14

250

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
dipenparmar12
  • 3,042
  • 1
  • 29
  • 39
Bar Horing
  • 5,337
  • 3
  • 30
  • 26
43

if you are using Linux system, use sudo command

sudo npm i -g npx
Rajitha Fernando
  • 1,655
  • 15
  • 14
14

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.

  1. user defined directory where npm will install packages

    mkdir ~/.npm-global
    
  2. configure npm

    npm config set prefix '~/.npm-global'
    
  3. add directory to path

    echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.profile
    
  4. refresh path for the current session

    source ~/.profile
    
  5. 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.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
dipenparmar12
  • 3,042
  • 1
  • 29
  • 39
4

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
Arafath
  • 100
  • 3
  • 9
  • 2
    Like the original question says : "npx : command not found". npx is literally not there. – jeancallisti Feb 03 '23 at 09:34
  • 1
    Because just like the original poster, I did download npm and I did install it. But, just like in the issue described, npx was "not there" (i.e. not found). The cause was some obscure Linux-related reason. To recap: When it says "command not found" then the issue is that command was not found. So "npx -v" will not work, and it's just reproducing the original problem. – jeancallisti Feb 13 '23 at 12:00
4

if you are using macOS, use sudo command

sudo npm install -g npx

enter image description here

Golam Sorwar
  • 1,255
  • 15
  • 12
2

Either delete the path from user variable or correct the right path Restart CMD and it should work.

 (C:\Program Files\nodejs).
ND verma
  • 171
  • 1
  • 9
0

Updating node helped me, whether that be from the command line or just re-downloading it from the web

Brian Sunbury
  • 45
  • 2
  • 9
0

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.

aalaap
  • 4,145
  • 5
  • 52
  • 59
0

sudo apt install npm install npm first

(it will take around 177MB node also will get installed along with this cmd) space

Install npx sudo npm i -g npx

Check the version of the installed npm,node,npx (for confirming latest release and installed or no it will show) using nod -v npx -v npm -v

Deepa Rokhade
  • 411
  • 4
  • 4
0

1. First step: check and install your node version with node -v.

2. second step: check and install your npm version with npm -v. If you still have a problem,might your command is npx create_react_app your_app_name instead of npx create-react-app your_app_name.

Omid Ostovari
  • 342
  • 2
  • 9
0

check node -v,npm -v, npx -v if are you getting output in the terminal but if you are executing these commands inside terminal of any IDE's like VSCODE, ATOM ... etc then reinstall that IDE.

subhashis
  • 4,629
  • 8
  • 37
  • 52
0
  • I went to the documentation of vs-code (mentioned below on recourses section)
  • Initially they ask to check the execution policy by executing Get-ExecutionPolicy on power shell of vs-code -> I got Restricted
  • Next Get-ExecutionPolicy -List to get all of the execution policies with their scorps. And I got the follwing result :/

MachinePolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Undefined

  • Then I rechecked the error which was displayed at the beginning, in vs-code power shell

    'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied. To change the execution policy
    execution policy for the current user, run "Set-ExecutionPolicy -Scope CurrentUser".

  • In there too it's mentioned the err is about the current-user

  • So I execute Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

  • And it worked for me. It's pleasure if this would work to you too thanks.

Recourses: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2

Damika
  • 622
  • 2
  • 8
  • 17
0

Go To Program Files And Go to Nodejs folder. There will be a powershell file called npm and even npx you can run all npm and npx commands in the respective powershells

Ozone
  • 1
-3

try :

sudo su

then

npm i npx 
or 
npi i -g npx

check your npx version by

npx -v