hql

Member
Jun 6, 2013
10
0
1
cPanel Access Level
Root Administrator
Hi,

I installed nodejs10 via WHM>easyapach 4 then tried to run the commands node -v from cpanel of one domain in the server and got error command not found, so what I want to know has nodejs been installed globally?

I managed to run the command node -v as
Code:
/opt/cpanel/ea-nodejs10/bin/node -v
but when i tried the same full path for npm
Code:
/opt/cpanel/ea-nodejs10/bin/node -i
im getting the attached errors so can anyone explain what the errors are and how I can fix them?
 

Attachments

cPanelHB

Technical Analyst
Staff member
Sep 6, 2018
42
7
83
Houston
cPanel Access Level
Root Administrator
Hello @hql,

Node should be installed and available to everyone on the server. However, the way the shell finds the executable for the "node" command relies on the $PATH environment variable.

By default, your $PATH environment variable won't contain the subfolders in /opt/. You can add it with the following command: export PATH=/opt/cpanel/ea-nodejs10/bin/:$PATH

If you want this added to your $PATH during login, you can add that to your ~/.bashrc file. Note that it won't take effect until your next login, or until you source your ~/.bashrc file.

Does that resolve the issue for you?
 

hql

Member
Jun 6, 2013
10
0
1
cPanel Access Level
Root Administrator
Hi, thanks for your response, I only used that path because you suggested it to another member in another post so thought It would apply to us also in this situation (SOLVED - Installing a Node.JS application on cPanel verison 80)

with the path you suggested above I can get the ...node -v to run just fine and it shows the version installed but ...npm -i produces all the errors in the picture above and I don’t quite know what they mean or what I’m doing wrong, could you take a look at the screen shot from my first post and tell me what is wrong ?
 

cPanelHB

Technical Analyst
Staff member
Sep 6, 2018
42
7
83
Houston
cPanel Access Level
Root Administrator
with the path you suggested above I can get the ...node -v to run just fine and it shows the version installed but ...npm -i produces all the errors in the picture above and I don’t quite know what they mean or what I’m doing wrong, could you take a look at the screen shot from my first post and tell me what is wrong ?
To clarify, I wasn't referring to the "path" as in /opt/cpanel/ea-nodejs10/bin/node, I mean the $PATH environment variable.

The error in your screenshot is saying that "there is no node binary in the current PATH", which is referring to the environment variable available to the npm process.

You can check the current environment variable in your shell by running a command like echo $PATH.

For example, on my test server:

Code:
[[email protected] ~]$ echo $PATH
/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/cpanel/composer/bin:/home/cptest/.local/bin:/home/cptest/bin
However, if I add the line I mentioned to my .bashrc file and then log out and back in:

Code:
[[email protected] ~]$ echo 'export PATH=/opt/cpanel/ea-nodejs10/bin/:$PATH' >> ~/.bashrc
[[email protected] ~]$ exit
logout

(then log back in):
[[email protected] ~]$ echo $PATH
/opt/cpanel/ea-nodejs10/bin/:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/cpanel/composer/bin:/home/cptest/.local/bin:/home/cptest/bin
Now /opt/cpanel/ea-nodejs10/bin/ is a part of the $PATH environment variable, which should resolve the error in your screenshot.

Does that resolve your issue?
 

hql

Member
Jun 6, 2013
10
0
1
cPanel Access Level
Root Administrator
Hi,

Thank you for your help, yes this works but it only seems to work in the account i run the above command, so i added the path into the .bash file as you said in WHM so thought it would work on all accounts that have terminal access but when i logged into another account via cpanel and ran the node -v command it wouldnt work and i had to add the full path to the $path like you explained again. So is there anyway to add this globally for all users?
 

cPSamuelM

Technical Analyst Team Lead
Staff member
Nov 20, 2019
196
38
103
USA
cPanel Access Level
Root Administrator
Hello @hql,

To add nodejs to the path for all users, you can use /etc/profile. For example:

# echo 'export PATH=/opt/cpanel/ea-nodejs10/bin/:$PATH' >> /etc/profile

I hope you find this helpful. Please let us know if you have any questions.

Best regards