Node.js: How to install NPM - node.js

I have cygwin and node.exe (0.5.7) installed on my window XP.
When I git clone npm(1.0.30), cd npm, then "make install", there are lots of node_modules cloning.
But it stopped when execute "node cli.js install git+https://github.com/isaac/ronnjs.git".
The following is my npm-debug.log.
info it worked if it ends with ok
verbose cli [ 'E:\node\node.exe', verbose cli
'e:\github\npm\cli.js', verbose cli 'cache', verbose cli
'clean' ] info using npm#1.0.30 info using node#v0.5.7
verbose config file C:\Documents and Settings\zhangchiqing.npmrc
verbose config file E:\etc\npmrc ERR! prefix directory not
found ERR! Error: ENOENT, �����ɹ����ɡ� ERR! 'E:' ERR!
Report this entire log at: ERR!
http://github.com/isaacs/npm/issues ERR! or email it to: ERR!
npm-#googlegroups.com ERR! ERR! System Windows_NT
5.1.2600 ERR! command "E:\node\node.exe" "e:\github\npm\cli.js" "cache" "clean" ERR! cwd E:\github\npm ERR! node -v v0.5.7
ERR! npm -v 1.0.30 verbose exit [ 1, true ]

This works in Ubuntu. You have to use older version of node.
sudo apt-get install -y g++ libssl-dev apache2-utils curl git-core
git clone git://github.com/joyent/node.git
cd node
git checkout v0.4.11
./configure
make
sudo make install
node -v
curl https://npmjs.org/install.sh | sudo sh
npm -v

Related

NPM install permission denied error using root user

So I've made a fresh installation of npm/node on my local machine using NVM using root user and everything looks fine, now my issue is when I tried to install using npm install --unsafe-perm -verbose command on my project folder error displays in my terminal.
npm verb stack Error: Command failed: /usr/bin/git clone --depth=1 -q -b 0.0.7 https://github.com/Mango/emitter.git /root/.npm/_cacache/tmp/git-clone-28a98ad9
npm verb stack fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-28a98ad9': Permission denied
npm verb stack
npm verb stack at ChildProcess.exithandler (child_process.js:282:12)
npm verb stack at ChildProcess.emit (events.js:182:13)
npm verb stack at maybeClose (internal/child_process.js:957:16)
npm verb stack at Socket.stream.socket.on (internal/child_process.js:378:11)
npm verb stack at Socket.emit (events.js:182:13)
npm verb stack at Pipe._handle.close [as _onclose] (net.js:598:12)
npm verb cwd /web/nbltv
npm verb Linux 4.15.0-29-generic
npm verb argv "/root/.nvm/versions/node/v10.1.0/bin/node" "/root/.nvm/versions/node/v10.1.0/bin/npm" "install" "--unsafe-per" "-verbose"
npm verb node v10.1.0
npm verb npm v5.6.0
npm ERR! code 128
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b 0.0.7 https://github.com/Mango/emitter.git /root/.npm/_cacache/tmp/git-clone-28a98ad9
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-28a98ad9': Permission denied
npm ERR!
npm verb exit [ 1, true ]
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-08-20T01_36_33_496Z-debug.log
NPM version - 5.6
NODE version - 10.1
Any help would be much appriciated. Thanks!
Chown down your node_modules & do not run as sudo.
You should always have ownership of the .npm directory as NPM will refuse installing native modules with sudo as this can be a security risk.
Try sudo chown -R $(whoami) ~/.npm and see if this would work. (or sudo chown -R $(whoami) ~/.nvm if you're using nvm)
Or reinstall with a node version manager without root as recommended in the docs:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
Creating a new global storage in your user space is the recommended way of preventing this error. Don't use sudo or change ownership of locations.
$ mkdir ~/.npm-global
$ npm config set prefix '~/.npm-global'
$ export PATH=~/.npm-global/bin:$PATH
$ source ~/.profile
However, since you're using npm 5.6, this might be more relevant to you:
npx: an alternative to running global commands
If you are using npm version 5.2 or greater, you may want to consider npx as an alternative way to run global commands, especially if you only need a command occasionally. For more information, see this article about npx.
Source: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
#U-ways answer is very good but for people who use nvm
rather than:
sudo chown -R $(whoami) ~/.npm
do
sudo chown -R $(whoami) ~/.nvm
this works form me
This works for me
sudo chown -R $(whoami) ~/.npm

npm install canvas dies with "clang: error: no such file or directory: '{{}'"

I get this error while installing any node packages that run node-gyp rebuild:
SOLINK_MODULE(target) Release/canvas-postbuild.node
clang: error: no such file or directory: '{{}'
make: *** [Release/canvas-postbuild.node] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:810:12)
gyp ERR! System Darwin 14.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/arkadiy/node-canvas
gyp ERR! node -v v0.10.33
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok
I have npm 1.4.28 and all of /usr/local is chowned to me. clang is recent-ish:
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
The error is completely ungoogleable (seriously, try it) and I can't even tell where clang is being invoked because the stack trace is only for the callback handler. It seems like a shell substitution/xargs issue almost?
I would say your node/npm install is suspect. If you start from their github
https://github.com/Automattic/node-canvas
and download the repo
git clone https://github.com/Automattic/node-canvas.git
cd node-canvas
npm install .
notice the period in above command - that gets upstream dependencies
I just did this and all is well - if you get errors doing above then I suggest you expunge node/npm and install from source. The following steps give you such a clean node/npm install from source
to start fresh remove prior node and npm installs as well as these :
sudo mv ~/.npmrc ~/.npmrc_ignore
sudo mv ~/.npm ~/.npm_ignore
sudo mv ~/tmp ~/tmp_ignore
sudo mv ~/.npm-init.js ~/.npm-init.js_ignore
download source from : http://nodejs.org/download/
cd node-v0.10.33
define environment variable NODE_PATH as the dir for subsequent module installs
export NODE_PARENT=/some/desired/install/path_goes_here
export NODE_PARENT=/usr/local/bin/nodejs # use this ONLY if you MUST install as root (sudo)
export NODE_PARENT=${HOME}/nodejs-v0.10.33 # use this if you want to install modules as yourself
export PATH=${NODE_PARENT}/bin:${PATH}
export NODE_PATH=${NODE_PARENT}/lib/node_modules
./configure --prefix=${NODE_PARENT}
make
make install
which puts it into dir defined by above --prefix
when you use syntax : npm install -g some_cool_module
the -g for global installs it into dir $NODE_PATH and not your $PWD
IMPORTANT put above three export xxx=yyy
commands into your ~/.bashrc or some such to persist these environment variable changes
Turns out I had a literal LDFLAGS='{} -L/usr/local/opt/openssl/lib' because of something that wasn't being expanded by the shell. Never mind!

not able to install npm without sudo

I've installed node into a custom directory in my home folder called local per these instructions : https://gist.github.com/isaacs/579814
I've added the location to my PATH and it seems to work fine. I cannot however seem to get npm to install without sudo. From what I can tell it is trying to execute a command in /bin folder.
The command I am running from ~/local/npm is make install and I got the latest versions of both node and npm from github.
Can anyone assist here?
user#localhost [~/local/npm]# make install
rm -rf \
.building_ronn \
html/doc \
html/api \
man
scripts/doc-build.sh doc/api/npm-view.md man/man3/npm-view.3
make[1]: Entering directory `/home1/extrabol/local/npm'
node cli.js install ronn --no-global
npm ERR! Error: EROFS, mkdir '/bin/node'
npm ERR! at Error (native)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/npm/npm/issues>
npm ERR! System Linux 3.4.87-20140414.1.bh6.x86_64
npm ERR! command "node" "/home1/extrabol/local/npm/cli.js" "install" "ronn" "--no-global"
npm ERR! cwd /home1/extrabol/local/npm
npm ERR! node -v v0.11.14-pre
npm ERR! npm -v 1.4.10
npm ERR! path /bin/node
npm ERR! code EROFS
npm ERR! errno -30
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home1/extrabol/local/npm/npm-debug.log
npm ERR! not ok code 0
The Debug Log reports this
0 info it worked if it ends with ok
1 verbose cli [ 'node',
1 verbose cli '/home1/extrabol/local/npm/cli.js',
1 verbose cli 'install',
1 verbose cli 'ronn',
1 verbose cli '--no-global' ]
2 info using npm#1.4.10
3 info using node#v0.11.14-pre
4 verbose node symlink /home1/extrabol/local/node/node
5 error Error: EROFS, mkdir '/bin/node'
5 error at Error (native)
6 error If you need help, you may report this *entire* log,
6 error including the npm and node versions, at:
6 error <http://github.com/npm/npm/issues>
7 error System Linux 3.4.87-20140414.1.bh6.x86_64
8 error command "node" "/home1/extrabol/local/npm/cli.js" "install" "ronn" "--no-global"
9 error cwd /home1/extrabol/local/npm
10 error node -v v0.11.14-pre
11 error npm -v 1.4.10
12 error path /bin/node
13 error code EROFS
14 error errno -30
Figured it out. Looks like when I git cloned the npm files somehow I didn't have ownership over all of the files. a quick chown -R on the npm folder fixed the issue.

node.js npm error when installing plugins with -g

Trying to install express globally and gets this error. I'm running the node.js version 0.10.24 on my x86 qnap.
[/share/Qweb/Codiad/workspace/chat] # npm install express -g
npm ERR! Error: setuid user id does not exist
npm ERR! at /share/MD0_DATA/.qpkg/Optware/lib/node_modules/npm/node_modules/uid-number/uid-number.js:44:16
npm ERR! at ChildProcess.exithandler (child_process.js:635:7)
npm ERR! at ChildProcess.EventEmitter.emit (events.js:98:17)
npm ERR! at maybeClose (child_process.js:735:16)
npm ERR! at Socket. (child_process.js:948:11)
npm ERR! at Socket.EventEmitter.emit (events.js:95:17)
npm ERR! at Pipe.close (net.js:466:12)
npm ERR! If you need help, you may report this entire log,
npm ERR! including the npm and node versions, at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! System Linux 3.4.6
npm ERR! command "/opt/bin/node" "/opt/bin/npm" "install" "express" "-g"
npm ERR! cwd /share/MD0_DATA/Qweb/Codiad/workspace/chat
npm ERR! node -v v0.10.24
npm ERR! npm -v 1.3.21
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /share/MD0_DATA/Qweb/Codiad/workspace/chat/npm-debug.log
npm ERR! not ok code 0
npm tool does not work correctly in QNAP OS
The work-around is telling npm that QNAP does not support get or set user-id by modifying npm source code:
Open file uid-number.js in your editor:
/share/MD0_DATA/.qpkg/Optware/lib/node_modules/npm/node_modules/uid-number/uid-‌​number.js
Goto line 11 and replace uidSupport = process.getuid && process.setuid with uidSupport = false
QNAP lacks couple of system users available on Linux systems and hence some software does not work properly on QNAP with out-of-the-box configuration, node included.
Solution to your problem: create user nobody. You can use adduser -D -H nobody
or NAS's web ui.
Good luck!
Node.js v5.8.0 download page
try this: node-upgrade.sh
#!/bin/sh
URL=$1
[[ $URL =~ (node-v5\.8\.0-.*)\.tar\.gz$ ]] && TARFile=${BASH_REMATCH[0]} && DirName=${BASH_REMATCH[1]}
[[ $TARFile == "" ]] && echo "url is wrong" && exit
NodeJSPath=$(/sbin/getcfg nodejs Install_Path -f /etc/config/qpkg.conf)
wget --no-check-certificate $URL
tar zxf $TARFile -C $NodeJSPath
rm -r $NodeJSPath/node $TARFile
ln -s $NodeJSPath/$DirName $NodeJSPath/node
uidscript=$NodeJSPath/$DirName/lib/node_modules/npm/node_modules/uid-number/uid-number.js
script="$(cat $uidscript)"
echo "${script/", uidSupport = process.getuid && process.setuid"/, uidSupport = false}" > $uidscript
e.g.
my qnap nas is Intel x86-based series
sh ./node-upgrade.sh https://nodejs.org/download/release/v5.8.0/node-v5.8.0-linux-x86.tar.gz

Node.js : NPM Install Fails

I get this error if I run
curl http://npmjs.org/install.sh | sh
even with sudo.
cirk#cirk-Parallels-Virtual-Platform:~$ curl http://npmjs.org/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3902 100 3902 0 0 6138 0 --:--:-- --:--:-- --:--:-- 12546
fetching: http://registry.npmjs.org/npm/-/npm-1.0.18.tgz
0.4.9
1.0.18
Skipping 0.x cruft clean
! [ -d .git ] || git submodule update --init --recursive
node cli.js cache clean
node cli.js rm npm -g -f --loglevel error
node cli.js install -g -f
npm ERR! error installing npm#1.0.18 Error: EACCES, Permission denied '../lib/node_modules/npm/bin/npm.js'
npm ERR! Error: EACCES, Permission denied '../lib/node_modules/npm/bin/npm.js'
npm ERR!
npm ERR! Please use 'sudo' or log in as root to run this command.
npm ERR!
npm ERR! sudo npm "install" "-g" "-f"
npm ERR!
npm ERR! or set the 'unsafe-perm' config var to true.
npm ERR!
npm ERR! npm config set unsafe-perm true
npm ERR!
npm ERR! System Linux 2.6.38-10-generic
npm ERR! command "node" "/tmp/npm.1568/package/cli.js" "install" "-g" "-f"
npm ERR! cwd /tmp/npm.1568/package
npm ERR! node -v v0.4.9
npm ERR! npm -v 1.0.18
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /tmp/npm.1568/package/npm-debug.log
npm not ok
It worked
What should I do? I tried these with no success:
chown -R cirk /usr/lib/nodejs
// and also this
chown -R cirk /usr/lib/node_modules (node_modules is empty it tries to install NPM here or what)
actually it did something, as you can see it writes at the end It worked what is a big lie!
Why are you running that in /usr?
If you really need to, this page suggests you may run that as root, so that would be:
curl https://www.npmjs.com/install.sh | sudo sh
But you better make sure it won't break your system, before running that.
I screwed up the permissions on my npm installation, and had this error when reinstalling. I solved it in the crudest way: by liberally sudo rm -rfing any directory tree that gave me trouble, then recompiling node.js and reinstalling npm.
If all else fails, you could fall back to that.

Resources