bash: npm: command not found in cPanel Terminal - node.js

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.

First install NodeJS install on cPanel, WHM.
To install NodeJS from WHM, Goto Home /
Software /
EasyApache 4
And in Additional Packages find NodeJS.
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.

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.

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

Related

How can I install nodejs manually in Linux from terminal

I have downloaded Nodejs in my Linux VM from nodejs.org, I want to install it from terminal. VM have already installed node v0.12.18 manually by someone else, I don't know how to do that. As I am installing nodejs offline, I should not depend on that whether or not npm installed.
I have tried [location]~ npm install node-v15.6.0-linux-x64.tar.gz
Getting below error
[host#machinename ~]$ sudo npm install node-v15.6.0-linux-x64.tar.gz
npm WARN excluding symbolic link bin/npm -> ../lib/node_modules/npm/bin/npm-cli. js
npm WARN excluding symbolic link bin/npx -> ../lib/node_modules/npm/bin/npx-cli. js
npm ERR! addLocal Could not install /home/usermachinename/node-v15.6.0-linux-x64.tar.g z
npm ERR! Linux 3.10.0-1062.9.1.el7.x86_64
npm ERR! argv "/usr/local/lib/nodejs/node-v0.12.18-linux-x64/bin/node" "/usr/loc al/lib/nodejs/node-v0.12.18-linux-x64/bin/npm" "install" "node-v15.6.0-linux-x64 .tar.gz"
npm ERR! node v0.12.18
npm ERR! npm v2.15.11
npm ERR! path /tmp/npm-1637-a9cb4311/unpack-5a7f411732fb/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! enoent ENOENT, open '/tmp/npm-1637-a9cb4311/unpack-5a7f411732fb/package .json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /home/usermachinename/npm-debug.log
How can I fix this?
You can't install the file using npm install, but since you already have the compressed file for node, my answer will hopefully help you achieve your goal.
First of all you will have to extract the tar.gz file you have node-v15.6.0-linux-x64.tar.gz, to do so just navigate to the folder where the file placed in then do the below command.
tar xf node-v15.6.0-linux-x64.tar.gz
Since you're using Linux the below command will add the new extracted node to your path.
nano ~/.profile
Add the following lines to the end:
# NodeJS
export NODEJS_HOME=/{path_to_the_extracted_folder}/node-v15.6.0-linux-x64/bin
export PATH=$NODEJS_HOME:$PATH
Please make sure you change {path_to_the_extracted_folder} to the path where you extracted the compressed file in the previous step.
Finally you can click CTRL+C to exit nano, type y then click enter.
To refresh the profile file enter the below code
. ~/.profile
Finally
To make sure everything is working fine check the nodeJs version by entering this command node -v it has to print v15.6.0.
You will not have to worry about the previously installed node version since above steps will change the nodeJs path.

Why "npm install -g grunt-cli" doesn't work correctly?

I am having trouble using grunt in my projects. I am setting up an macos computer with version 11.0.1.
The project files (local) are in principle correct, since I use it on another computer and it works fine there.
I have been trying to solve this error for more than two days, the problem is that the local configuration does not work correctly, since I get the message ~ bash: grunt command not found when trying to initialize grunt with the grunt or grunt watch command
When trying to install grunt-cli globally I get this error:
npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path /Users/bertanicolau/.npm-packages
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, lstat '/Users/bertanicolau/.npm-packages'
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! /Users/bertanicolau/.npm/_logs/2020-11-23T17_06_23_295Z-debug.log
The .npm-packages folder does not exist in this location, instead the .npm folder does exist, I don't know why it is looking for another.
I've tried clearing the npm cache, I've also tried deleting the package-lock.json file and changing paths on .bash-profile but none of this seems to work.
Can it be a npm or node version bug?
$ npm -v && node -v
7.0.8
v15.2.1
Thanks!
In one of your .npmrc files, you probably have prefix=/Users/trott/.npm-packages. If so, leave it and create the directory with mkdir ~/.npm-packages. Or set it to a different directory. Or remove the entry entirely.
The places to look for the .npmrc file that may be causing this to happen:
per-project config file (/path/to/my/project/.npmrc)
per-user config file (~/.npmrc)
global config file ($PREFIX/etc/npmrc)
npm builtin config file (/path/to/npm/npmrc)

npm run serve failed

When I try to run "npm run serve" in my terminal on my Mac. I get following error message. It works fine for a couple a hours ago, but not now. can anyone help me?
npm ERR! syscall open
npm ERR! path /Users/MYNAME/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/MYNAME/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! /Users/MYNAME/.npm/_logs/2020-09-03T12_46_01_362Z-debug.log
First check on your filesystem if the file EXISTS.
for a new project, you always need to create a package.json, running
npm init
will create a package.json for you in the current directory.
if you want to instantly create a package.jsn using defaults, run
npm init -y
for more understanding refer this npm guide
If you say that everything worked before, then you are running this script in the wrong folder and npm cannot find package.json.
no such file or directory, open '/Users/MYNAME/package.json'
Use the correct folder.

npm start run in wrong path

First of all i'm using Ubuntu 14.04, and i create a node.js project under /home/user/project_folder.
When i type npm start /home/user/project_folder/, i get this error:
npm ERR! node v4.6.1
npm ERR! npm v4.0.2
npm ERR! path /home/user/package.json
npm ERR! code ENOENT
npm ERR! errno -2
no such file or dir..
Am'i doing it wrong? did i forget something?
Thank you.
npm doesn't take the path as an argument.
What you want is:
cd /home/user/project_folder && npm start
You can put it in a script, e.g. save this as /home/user/project_folder/run.sh:
#!/bin/sh
cd /home/user/project_folder && npm start
Change permissions with:
chmod a+x /home/user/project_folder/run.sh
And run it with just:
/home/user/project_folder/run.sh
Or without changing permissions:
sh /home/user/project_folder/run.sh
When you use npm start you don't need to specify the file path. You have to be on the directory of your project cd project_directory and there run npm start. Also make sure that in your package json, you have specified in the "start" property, the file to start.

Error: EACCES, permission denied even after using sudo?

I am trying to set up a chrome extension that will automatically save the changes I make to my website with the inspect element feature. The idea is that you'll be able to make real time changes to the website without having to go back into the ide to save the changes and re-upload and everything. The extension is called DevTools Autosave. I've been following the instructions from this site. I'm trying to install this on a mac.
I've installed node.js and the extension already. When I got to the part in the instructions where it talks about which commands to run in the terminal I've tried both with and without the "sudo" in front of the "npm install -g autosave" command but I always get this error:
Error: EACCES, permission denied
at Function.startup.resolveArgv0 (node.js:815:23)
at startup (node.js:58:13)
at node.js:906:3
npm ERR! autosave#1.0.3 install: `node ./scripts/install.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the autosave#1.0.3 install script.
npm ERR! This is most likely a problem with the autosave package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./scripts/install.js
npm ERR! You can get their info via:
npm ERR! npm owner ls autosave
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 14.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "autosave"
npm ERR! cwd /Users/Brent
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR! not ok code 0
Anyone know how I can fix this? I can't find anyone that is having this problem and I've been on a few different forums now but can't find a solution. Thanks in advance.
You have two options: Either fix your npm setup, so you can use npm -g, or install autosave locally.
To install locally (i.e. in node_modules within your current directory), run npm install autosave (without -g). Then you can run ./node_modules/.bin/autosave or ./node_modules/autosave/bin/autosave to start autosave.
To fix your npm setup, so you can use -g without root permissions (recommended):
In your home dir (assuming /Users/Brent/), create a file called .npmrc with the following content:
cache = /Users/Brent/.npm/cache
globalconfig = /Users/Brent/.npm/npmrc
globalignorefile = /Users/Brent/.npm/npmignore
prefix = /Users/Brent/.npm
And add ~/.npm/lib/node_modules to your NODE_PATH, e.g. by putting the following in .bashrc (assuming that your shell is bash) to allow the modules to be found, and append ~/.npm/bintoPATHso you can run any installed binary (i.e. runautosave` from anywhere):
export NODE_PATH=$HOME/.npm/lib/node_modules
export PATH=$PATH:$HOME/.npm/bin
(changes to .bashrc only take effect when you load the shell, or use . ~/.bashrc; if you want to use the new setup without reloading the shell, just run that line (export ...) in your current shell).
As of 2020, here is the recommended solution by npm. It worked for me (OSX). (No need to change any path configuration or .bashrc)
Steps:
Install nvm by running below command.
If you are using bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
If you are using zsh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | zsh
Install node using nvm (No need to uninstall existing node/npm)
nvm install 12.13.1

Resources