npm install throwing error in ubuntu - node.js

I'm trying to install a package using npm install -g PACKAGE_NAME but it is throwing the following error.
npm http GET https://registry.npmjs.org/ionic
npm http 304 https://registry.npmjs.org/ionic
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/ionic',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/lib/nodejs/fstream/lib/writer.js:171:23',
npm ERR! '/usr/lib/nodejs/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
Also when I tried sudo npm install -g PACKAGE_NAME , it executed silently but the package was not installed.
$ sudo npm install -g ionic
npm http GET https://registry.npmjs.org/ionic
npm http 304 https://registry.npmjs.org/ionic
/usr/local/bin/ionic -> /usr/local/lib/node_modules/ionic/bin/ionic
ionic#1.7.13 /usr/local/lib/node_modules/ionic
xarvis#xarvis:~/songhop/self$ ionic
/usr/bin/env: node: No such file or directory
Also As stated in an answer on stack overflow I've give write access in node_module directory using sudo chown -R $USER node_modules.

The first error says you are not root. If you want to add node modules as user avoid -g (global) in your npm command.
The second one is saying that it cannot find node. You need to do a symbolic link from nodejs to node while installing nodejs in ubuntu as:
sudo ln -s /usr/bin/nodejs /usr/bin/node
To test your node installation, type in terminal node -v to see the node version number.

Related

Getting error like 'Error eacces mkdir' while run 'npm install -g create-react-app' command

When I try to install reactjs by npm install -g create-react-app command in Ubuntu I am getting an error as following. please help me remove these error.
giving me this error-
npm ERR! Error: EACCES, mkdir '/home/veomit10/tmp/npm-6710-iquektSI'
npm ERR! { [Error: EACCES, mkdir '/home/veomit10/tmp/npm-6710-iquektSI']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/veomit10/tmp/npm-6710-iquektSI' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 4.4.0-144-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "react-native-cli"
npm ERR! cwd /home/veomit10/reactApp
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR! path /home/veomit10/tmp/npm-6710-iquektSI
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/home/veomit10/tmp/npm-6710-iquektSI'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/veomit10/reactApp/npm-debug.log
npm ERR! not ok code 0
Thanks in advance.
it seems you are trying to install it from a non-root user so in this case, you have to have the root permissions in order to install a global node modules.
just try to run commands from the root user, run this first
sudo su
after that run:
npm install -g create-react-app
if you still having error '/usr/bin/env: node: No such file or directory'
try to run this command ln -s /usr/bin/nodejs /usr/bin/node and re install creat-react-app again.

NPM install not working on OpenShift (via rhc ssh) (permissions)

Get into remote ssh via:
rhc ssh <myapp>
Need to intall a module:
npm install koa --save
Gives the result:
npm http GET https://registry.npmjs.org/koa
npm http 304 https://registry.npmjs.org/koa
npm WARN engine koa#0.19.1: wanted: {"node":">= 0.11.16","iojs":">= 1.0.0"} (current: {"node":"v0.11.11","npm":"1.3.25"})
npm ERR! Error: EACCES, mkdir '/var/lib/openshift/55397f875973ca0497xxxxxx/node_modules'
npm ERR! { [Error: EACCES, mkdir '/var/lib/openshift/55397f875973ca0497xxxxxx/node_modules']
npm ERR! stack: 'Error: EACCES, mkdir \'/var/lib/openshift/55397f875973ca0497xxxxxx/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! path: '/var/lib/openshift/55397f875973ca0497xxxxxx/node_modules',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/var/lib/openshift/55397f875973ca0497xxxxxx/node_modules/koa',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/var/lib/openshift/55397f875973ca0497xxxxxx/app-root/data/node-v0.11.11-linux-x64/lib/node_modules/npm/node_modules/fstream/lib/writer.js:171:23',
npm ERR! '/var/lib/openshift/55397f875973ca0497xxxxxx/app-root/data/node-v0.11.11-linux-x64/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:97:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
The error says it all: Error: "EACCES, mkdir '/var/lib/....'". npm is trying to make a directory with the 'mkdir' command. Normally this needs specific privileges.
Run the npm install with sudo and you should be good to go!
sudo npm install koa --save
Also it is looking for "node":">= 0.11.16","iojs":">= 1.0.0" and you have "node":"v0.11.11"
Try a version manager like so:
sudo npm install n -g
sudo n 0.4.12 // replace with the version you want
or you could specify 'stable' to get the latest stable build:
sudo npm install n -g
sudo n stable

npm install is not working

I used this installation guide to install nodejs:
https://github.com/joyent/node/wiki/installing-node.js-via-package-manager#debian-and-ubuntu-based-linux-distributions
I am trying to use npm install and I had this error when I used this command:
npm install --global yo bower grunt-cli
npm ERR! Error: EACCES, mkdir '/home/alexfqc/.npm-packages/lib/node_modules'
npm ERR! { [Error: EACCES, mkdir '/home/alexfqc/.npm-packages/lib/node_modules']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/alexfqc/.npm-packages/lib/node_modules',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/home/alexfqc/.npm-packages/lib/node_modules/grunt-cli',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/lib/node_modules/npm/node_modules/fstream/lib/writer.js:171:23',
npm ERR! '/usr/lib/node_modules/npm/node_modules/mkdirp/index.js:46:53',
npm ERR! 'Object.oncomplete (fs.js:108:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
I was following the yeoman instructions, and there is a page for this error
After do this steps the error still continue.
Then I tried this commands:
sudo chmod -R 755 /home/alexfqc/.npm-packages
sudo chown -R root /home/alexfqc/.npm-packages
and did not work.
I am trying the entire day install nodejs correctly to use yeoman, bower and grunt but it seems impossible.
I tried other ways of installing nodejs but another error appeared.
I anyone could help to fix this error or show a way to install the nodejs, yeoman, bower and grunt I would be very grateful.
You have an access error, try using sudo npm install --global yo bower grunt-cli to perform install as root
Alternate - Instead of giving ownership of folder to root, give it to your user account with: sudo chown -R $USER /home/alexfqc/.npm-packages

Error installing yeoman

Installing Yeoman on my OSX machine results in the following error:
paulh16$ npm install -g yo
npm http GET https://registry.npmjs.org/yo
npm http 304 https://registry.npmjs.org/yo
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/yo'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/yo']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/yo',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/yo',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 13.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "yo"
npm ERR! cwd /Users/paulh16/.rvm/lib
npm ERR! node -v v0.10.22
npm ERR! npm -v 1.3.14
npm ERR! path /usr/local/lib/node_modules/yo
npm ERR! fstream_path /usr/local/lib/node_modules/yo
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/yo'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/paulh16/.rvm/lib/npm-debug.log
npm ERR! not ok code 0
I believe the problem is that bash is looking for npm within the Ruby Version Manager, which is where I installed node and npm originally. However, I removed both from RVM and installed from the Node website. I also adjusted my .bash_profile:
PS1="\u$ "
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
fi
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM$
I don't understand why the Yeoman installation is failing.
This solved the issue for me. Setting the permission on the npm folder in your home directory was the fix for me.
sudo chown -R `whoami` ~/.npm
The npm command fails because you need to be root to edit files under /usr/.
You should properly configure npm, see this relevant SO answer:
$ echo prefix = ~/.node >> ~/.npmrc
try
sudo chown -R $USER /usr/local
and this kind of problem would be solved forever
it's not encouraged to npm with sudo
For me on Ubuntu only the following worked for me...
Ubuntu
Tested on Ubuntu 14.04.2
This was a base install of Ubuntu 14.04.2 on VirtualBox using ubuntu-trusty-64.
I had just installed node and npm fresh and they were working well.
npm install -y -g yo
echo export PATH="$HOME/npm/bin:$PATH" >> ~/.bashrc
npm config set prefix ~/npm
echo "export NODE_PATH=$NODE_PATH:/home/$USER/npm/lib/node_modules" >> ~/.bashrc && source ~/.bashrc
npm install -y -g yo
yes I had to install yeoman, fix the path issues, then reinstall yeoman.
based on some answers on this stack overflow post
This worked well for me:
sudo npm install -g yo

Why can't i npm install nodemon or supervisor on OSX 10.8.4?

I'm just trying to install nodemon or supervisor using terminal, and I keep getting this error which I don't understand. I tried running as the administrator with sudo npm install supervisor -g which seemed to work, but than didn't when i deleted/added some js code. Any ideas?
Squirrels-MacBook-Air:lesson7_examples Squirrel$ npm install nodemon -g
npm http GET https://registry.npmjs.org/nodemon
npm http 304 https://registry.npmjs.org/nodemon
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/nodemon'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/nodemon']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/nodemon',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/nodemon',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 12.4.1
npm ERR! command "node" "/usr/local/bin/npm" "install" "nodemon" "-g"
npm ERR! cwd /Users/Squirrel/Documents/Code/Memry/Memry_Mongoose
npm ERR! node -v v0.10.21
npm ERR! npm -v 1.3.11
npm ERR! path /usr/local/lib/node_modules/nodemon
npm ERR! fstream_path /usr/local/lib/node_modules/nodemon
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/nodemon'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Squirrel/Documents/Code/Memry/Memry_Mongoose/npm-debug.log
npm ERR! not ok code 0
Squirrels-MacBook-Air:lesson7_examples Squirrel$
P.S. I'm running this on a pre-existing template and my dependencies are
"dependencies": {
"mongoose": "~3.6.15",
"express": "~3.3.4",
"jade": "~0.34.1",
"email-validator": "~0.1.2"
}
When I tried sudo this is what happened:
sudo npm install supervisor -g --save
Password:
npm http GET https://registry.npmjs.org/supervisor
npm http 304 https://registry.npmjs.org/supervisor
/usr/local/bin/node-supervisor -> /usr/local/lib/node_modules/supervisor/lib/cli-wrapper.js
/usr/local/bin/supervisor -> /usr/local/lib/node_modules/supervisor/lib/cli-wrapper.js
supervisor#0.5.6 /usr/local/lib/node_modules/supervisor
Which seemed to work. But than in the application code I began to add and delete javascript and click save, yet the effects wouldn't take place unless I restarted the server within terminal.
Late to the party, but it is important to note that you should avoid using sudo when npm installing. It is a huge security risk to sudo npm install as you are giving arbitrary scripts root access to your machine.
Instead you should make yourself the owner of the directories in which the NPM
sudo chown -R $USER /usr/local
and then
sudo chown -R $USER ~/.npm
Now you should be able to run the commands without sudo:
npm install supervisor -g --save
You're encountering an EACCES error, which means you don't have the rights to create a directory in /usr/local/lib/node_modules/nodemon as a standard user in Mac OS X.
There are two solutions:
Run the same command as a superuser, using sudo. The package will be installed in /usr/local/lib/node_modules.
Change npm's settings to install all of your global packages into one of your private folders, that your user has ownership of. See this relevant answer that explains step-by-step the process.
I know I'm late to the question, but you should check out nvm (node's answer to rbenv or virtualenv).
Install:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
Then add . ~/.nvm/nvm.sh to your ~/.bashrc, ~/.profile, or ~/.zshrc
Usage:
If you wanted to use version 0.10, run nvm install 0.12.7 (or nvm install stable), then nvm use 0.12.7.
Install your libs, EACCESS error-free, and go to town. npm install -g supervisor works just fine!
To load a specific version default in new tabs, use the command nvm alias default 0.12.7

Resources