bash: npm: command not found in cPanel Terminal
Asked Answered
S

3

5

I get response, When try to write:

$ /opt/cpanel/ea-nodejs16/bin/npm -v
8.1.2

but with :

$ npm -v
bash: npm: command not found

So, I tried as the same logic but it didn't work:

$ /opt/cpanel/ea-nodejs16/bin/npm install
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/mydomain/public_html/app/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/mydomain/public_html/app/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/mydomain/.npm/_logs/2022-03-02T14_43_55_155Z-debug.log

So, how to make " npm " command lines works on server.

Somerville answered 2/3, 2022 at 15:1 Comment(1)
The error message looks clear in this case. Your currently directory doesn't have a package.json file.Pontificate
E
14

First install NodeJS install on cPanel, WHM.

To install NodeJS from WHM, Goto Home / Software / EasyApache 4

And in Additional Packages find NodeJS.

enter image description here

After that create an environment variable which points to the node directory. Run this command to do that.

export PATH=/opt/cpanel/ea-nodejs16/bin/:$PATH

Finally run npm -v to check NodeJS version.

Hope this will help for someone.

Equipoise answered 8/9, 2022 at 9:2 Comment(1)
This was very helpful. I was not aware that it will be installed in in /opt/cpanel/ directory. but now it makes sense, all the additional packages resides here. ThanksBaziotes
C
7

You need to create an environment variable which points to the right directory. This should do the job:

export PATH=/opt/cpanel/ea-nodejs16/bin/:$PATH

or add it to your .bashrc file to keep it persistent. And regarding this npm error you get, as jordanm mentioned you don't have package.json file in you current directory.

Chekhov answered 2/3, 2022 at 15:11 Comment(0)
C
2

You have to store the path inside in your .bashrc file. You can do it easily by run following command.

echo export PATH=/opt/cpanel/ea-nodejs16/bin/:$PATH
Current answered 5/9, 2022 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.