No such file or directory error for npm - npm

I think I have installed npm.. But when I try to type npm -v ,it shows
-bash: /usr/local/bin/npm: No such file or directory
How to fix that.. node -v works fine... The terminal shows
v0.12.4
Can anyone help me ...

I have fixed that problem by reinstall node and npm. For mac user, try to type
sudo curl -L npmjs.org/install.sh | sudo sh
Hope it works.

Related

NPM Command Not Found in bash command

I made the mistake of updating npm today and now whenever I try to use any commands that start with npm the terminal returns with "npm: command not found." I am running node -v 13.13.0, I have tried to install npm again however, any time I use npm the terminal returns "npm: command not found." I am using bash in the terminal. Does anyone have any ideas how to troubleshoot this issue? Thanks!
Resolved: I had to reinstall node.js, didn't think to try that first, my bad.

I can see that nvm and npm is not installed after succesfull installation

I am installing nvm and npm like this:
curl https://raw.githubusercontent.com/creationix/nvm/v0.11.1/install.sh | bash
echo "[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh" >> /home/deployer/.profile
source /home/deployer/.profile
# source ~/.nvm/nvm.sh
nvm install v0.12.9
nvm use v0.12.9
nvm alias default v0.12.9
curl -L https://npmjs.org/install.sh | sh
with bash and clearly see a successfull installation ("It worked" prompt), but after it stops and I type nvm or npm in the console I get:
No command 'nvm' found, did you mean:
The program 'npm' is currently not installed.
If I write this in the console:
source /home/deployer/.profile
nvm starts working, but why I need to repeat this process, not sure.
This suggests that your shell is not sourcing .profile for you. Perhaps you're using a non-login shell; perhaps your OS sources a different file when logging in.
What happens if you add . $HOME/.profile to your .bashrc, for example?

apidocjs not returning anything in response

I have installed 'apidoc' after installing 'npm' and 'node' for my API documentation by the help of following command:
npm install apidoc -g
After installing apidoc globally, I simply ran below command on my project directory (assuming apidoc will consider its default template file):
apidoc
In result no errors and no documentation generated.
Similarly, I have tried:
apidoc -i ~/PROJECTS/jruby/project/webservice/ -o ~/PROJECTS/apidocs/apidoc/ -t ~/PROJECTS/apidocs/mytemplate/
But nothing happens, in that case I had nothing on 'mytemplate' directory.
Can you guys please tell me what I've missed to install/consider? and why nothing is appearing on command execution?
Note: I'm using this for my ruby application, but unable to install its gem as we're running our application on ruby 1.9 and it requires ruby 2.0. I need an independent solution that should works for other projects as well.
Thank you.
I got the solution; copied 'package.json' file from https://github.com/apidoc/apidoc and ran below command for npm
npm install
after getting success install nodejs properly by following steps:
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install nodejs
then went to the project directory and ran the following command:
apidoc
after success of above command got html document in doc/ directory inside project. Cheers !

-bash: yo: command not found

Like a lot of people I am also having issues with Yeoman.
Error -bash: yo: command not found in OSx.
I tried adding export PATH=/usr/local/share/npm/bin:$PATH on my .bash_profile as suggested by some folks and still same error.
I've lost 2 hours of my productivity trying to fix Yeoman bugs and still nothing.
Does anyone know any good solution that fixes the -bash: yo: command not found ?
I found that for recent versions of npm, all node packages are installed in the ~/npm/bin/ directory.
So add those lines to your $PATH in the .profile file :
export PATH=$PATH:~/npm/bin
Then do :
source ~/.profile
yo -v
Finally found a solution for this.
First I had to uninstall and install yo again:
npm remove -g yo
npm install -g yo
I also added a symlink to the bash_profile to make yo work. The following line: PATH=${PATH}:~/.node/bin After that restart the prompt for the change to take action.
Please check this for more references: Why are my Yeoman generators installing in the wrong place?
try to add an symbolic-link (ln -s) into the /sbin -directory.
like:
ln -s /sbin/ /usr/local/share/npm/bin/yo
This also seems to work :)
sudo `yo angular2-ts [appname]`
where [appname] is the name of your app (without the []) :)
just give access for the user to read write execute in the folder webapp
sudo chmod 777 webapp
cd webapp
yo angular [appname]

How to fix EACCES issues with npm install

Some of my node modules get installed but there are always these sort of issues on this particular linux mint machine
npm install
npm ERR! Error: EACCES, open '/home/me/.npm/semver/3.0.1/package/package.json'
npm ERR! { [Error: EACCES, open '/home/me/.npm/semver/3.0.1/package/package.json']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/me/.npm/semver/3.0.1/package/package.json',
npm ERR! parent: 'gulp' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
This code fix it for me.
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
UPDATE. See
this answer
for a better way.
You have to set correct permissions (ownership) so npm can access your (sub)directories with your normal user permissions:
sudo chown -R $USER <directory>
where in your case <directory> is /home/me and -R is for recursive to also change ownership of all your subdirectories, which is exactly what you want. That should fix the EACCESS issue.
Sadly the advise to run the command as root/Administrator is wrong here.
You want to avoid running npm with sudo ever, as recommended by the npm creator Isaac Schlueter:
I strongly encourage you not to do package management with sudo! Packages can run arbitrary scripts, which makes sudoing a package manager command as safe as a chainsaw haircut. Sure, it’s fast and definitely going to cut through any obstacles, but you might actually want that obstacle to stay there.
See here for more details.
Add sudo before npm install . It will permit access to write .
sudo npm install [name of package].
Try to use "sudo npx create-react-app app-name"
it may still show error because some dependencies may be mising but a directory and the necessary files maybe created.
Set the correct permission to access the necessary directories.
In my case (Node & NPM Installation via Brew) on BigSur:
sudo chown -R $USER /Users/YOUR_USERNAME/node_modules
If you are still facing problem after running :
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
Run the npm install command with :
--unsafe-perm
which will help you in installing the package with out any problem.
To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory.
Back up your computer.
On the command line, in your home directory, create a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
In your preferred text editor, open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.profile
To test your new configuration, install a package globally without using sudo:
npm install -g jshint
(ref: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally)
Running the code in sudo mode have fixed the problem for me
$ sudo npm install -g nativefier
And if you have related issues like package unmet dependencies check out this link
in windows run cmd as administrator and then try:
npm install -g <package-name>
in mac os or linux try:
sudo npm install -g <package-name>
I understand one might be suspicious about changing the ownership of folders situated in the system files. But it's completely safe, they are meant to host processes that you can use without sudo. So I prefer this solution because it's good and will guarantee compatibility after.
sudo chown -R $USER /usr/local/bin
sudo chmod -R 0775 /usr/local/bin
sudo chown -R $USER /usr/local/lib/node_modules
sudo chmod -R 0775 /usr/local/lib/node_modules
If you installed a new version of node.js, you could still get some error. Try deleting the npm cache:
sudo npm cache clear
To permanently fix this problem, please run:
sudo chown -R 1000:1000 "/home/$USER/.npm"
sudo npm install -g create-react-app
just adding sudo before nmp install will give superuser privilages to run npm and that would not cause any erros while it want to alter a file or access it. well, i hope this might help you!
I had the Similar Problem when I typed:
npm install -g create-react-app
The Terminal replied:
npm ERR! code EACCES
....
So I add "sudo" like This:
sudo npm install -g create-react-app
And problem Solved!! :-)
(So I am agree with "chethan chandan" about using "sudo")