67

I'm learning laravel and follwing this tutorial,

But when I went try and install npm, is says bash: npm: command not found

enter image description here

4

11 Answers 11

34

If you have already installed nodejs and still getting this error. npm: command not found..

run this

apt-get install -y npm
5
  • 7
    Don't forget to sudo!
    – ledawg
    Commented Aug 17, 2019 at 10:43
  • 6
    yeah but what if you're using git bash
    – Oneezy
    Commented Feb 13, 2020 at 14:04
  • 1
    If you're using GitBash, exit first, the open it again and try to run npm -v after installing from the npmjs site (its already one package -nodejs and -npm).
    – Kris
    Commented Jul 10, 2020 at 16:32
  • 1
    Question has tag "windows" and you're giving linux commands. Commented Jun 16, 2023 at 21:14
  • This gave me old version on Ubuntu. So I followed the official guides to install node/npm - docs.npmjs.com/downloading-and-installing-node-js-and-npm
    – imy
    Commented Jan 30 at 17:59
20

I also come here for the same problem, The solution I found is to install npm and then restart the Visual Studio Code

1
  • 1
    For people who wanna copy and paste the command, you install npm using sudo apt-get install -y npm.
    – Ishidres
    Commented Aug 14, 2022 at 17:16
11

I am following the same tuturial and I had this issue and how I solved is just download the

8.11.4 LTS version

from this link then install it then the command worked just fine!

3
  • My problem was that I did not install the node.js, all you need to do for this is to just install node.js - npm page
    – Deo
    Commented Aug 29, 2018 at 1:12
  • Exactly, That is what I meant by installing the 8.11.4 LTS version. Commented Sep 2, 2018 at 16:35
  • In my case isn't owrking... Commented Oct 14, 2022 at 11:21
8

in redhat base OS (tested in centos 7)

yum install nodejs npm -y

in debian base OS

apt-get install -y npm    
1
  • This worked for me on a centos server with cpanel. Thanks man ;-) Commented Nov 13, 2019 at 15:30
6

I know it's an old question. But it keeps showing in google first position and all it says it's "install node.js". For a newbie this is not obvious, so all you have to do is go to the node.js website and search for the command for your linux distribution version or any other operating system. Here is the link: https://nodejs.org/en/download/package-manager/

In this page you have to choose your operating system and you'll find your command. Then you just log into your console as a root (using putty for instance) and execute that command.

After that, you log as normal user and go again inside your laravel application folder and run again npm install command, and it should work. Hope it helps.

1
  • This is the real answer for this issue. Appreciate your help
    – Ahsan
    Commented Jan 17, 2022 at 15:59
3

If you already installed npm globally on your system, and you are still getting the above error message by using VSCode terminal. Just close your VSCode application and reopen again, that should resolve the issue.

0
2

The solution is simple.

After installing Node, you should restart your VScode and run npm install command.

1
  • After trying so many things (I'd already installed npm/Node), it was as simple as making sure I'd shut down VSCode and then reopening it. It worked in Terminal after then.
    – elarcoiris
    Commented Feb 9, 2023 at 7:55
2

First You need to check the node version using terminal (not gitbash)

node --version

npm --version

if those exists, Restart your pc and check

Cheers !!

1
  • This is working perfectly for me.... Commented Aug 23, 2023 at 10:31
0

In my case it was entirely my fault (as usual) I was changing the system path under the environment variables, in Windows, and messed up the path for Node/NPM. So the solution is to either re-add the path for NPM, see this answer or the lazy option: re-install it which will re-add it for you.

0

maybe vscode config shell failed, you can try restart it.

0

Maybe you should change to zsh. Write in command line zsh , then again npm i.

Not the answer you're looking for? Browse other questions tagged or ask your own question.