How to install npm in cPanel with terminal command
The npm
command may not be installed on your cPanel server, or the system’s PATH
may not be configured to recognize it.
To resolve this issue, follow these steps:
- Check if Node.js and npm are installed: Run the following commands to check if Node.js and npm are installed:
node -v npm -v
If these commands return version numbers, then Node.js and npm are installed. If you getcommand not found
, proceed with the next steps. - Install Node.js and npm: If
npm
is not installed, you can install it manually by following these steps:- First, check if you have access to install packages on your cPanel server. If so, use SSH to log in to the server.
- Use the following commands to install Node.js (which includes npm) via
nvm
(Node Version Manager):curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
After running this script, you’ll need to close and reopen the terminal or run:source ~/.bashrc
- Then, install the latest stable version of Node.js:
nvm install node
- Verify the installation:
node -v npm -v
- Ensure npm is in the PATH: If npm is installed but the system cannot find it, make sure it is in the system’s
PATH
. You can add the following lines to your.bashrc
or.bash_profile
file:export PATH=$PATH:/usr/local/bin
Then, run:source ~/.bashrc
- Check cPanel’s Node.js Manager: Some cPanel servers have a Node.js manager built into the interface. You can check in the cPanel dashboard for an option under Software -> Setup Node.js App, where you can create an environment for Node.js apps and use npm there.
After following these steps, you should be able to use the npm
command in your terminal.