I have just reinstalled Ubuntu 12.04 LTS, and before anything else i did these steps:
Installed Node via package manager with the following script
sudo apt-get update sudo apt-get install python-software-properties python g++ make sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs
Tried to install yeoman, express, n, yeoman's generators globally and all of them returned the same error
npm ERR! Error: EACCES, symlink '../lib/node_modules/n/bin/n'
npm ERR! { [Error: EACCES, symlink '../lib/node_modules/n/bin/n'] errno: 3, code: 'EACCES', path: '../lib/node_modules/n/bin/n' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 3.8.0-29-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "-d" "n"
npm ERR! cwd /home/heberlz
npm ERR! node -v v0.10.20
npm ERR! npm -v 1.3.11
npm ERR! path ../lib/node_modules/n/bin/n
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, symlink '../lib/node_modules/n/bin/n'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/heberlz/npm-debug.log
npm ERR! not ok code 0
Reclaimed ownership of the following folders recursively ~/.npm, /usr/lib/node, /usr/lib/node_modules, and of the following symlinks /usr/bin/node, /usr/bin/nodejs with absolutely no success
I need to install yeoman and its generators without sudo not to be in trouble later on :(
This issue and other caused by the same reason can be solved installing Node in user space.
You can do it just copying and pasting in your terminal
Same commands can be launched also to get Node updated to latest version.
Don't forget to edit your environment. Only once, do
Check out this article as a reabout how to Install Node.js without sudo.
For a more general solution about this topic (i.e., install software locally) see dotsoftware.
As for October 2014:
Node.js is available from the NodeSource Debian and Ubuntu binary distributions repository.
That's it.
Outdated answer:
The fastest way without using sudo is like described here by isaac
EDIT:
There are certain security concerns and functionality limitations regarding changing the ownership of /usr/local to the current user:
Having said that, if you want to install global module without using sudo, I don't see any better solution (from pragmatic point of view) than mentioned. Security vs easy of use is very broad topic, and there is no easy answer for that - it just depends on your requirements.
If you already have
$HOME/bin
in your path, a simpler solution is just ...$HOME/bin
directory.Since this discussion is really about reducing the security risks of running
sudo
, you should also be aware that any node app could potentially be installing an app name that does not match the registered node package name you think you're installing. So there is a security risk that annpm install
will replace an existing system command or one you already have in$HOME/bin
. If you're concerned, check thebin
, andscripts
properties in thepackage.json
file of the app you're installing first.In general, it's safest to:
$HOME/bin
last in your path so system commands are not superseded.$PATH
so you don't accidentally run a command that happens to be in the current directory.Reference:
Find the path to npm's directory:
For many systems, this will be /usr/local.
Change the owner of npm's directories to the name of the current user (your username!):
This changes the permissions of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).
Here is the link for full details
https://docs.npmjs.com/getting-started/fixing-npm-permissions
The best solution I found was to install Node.js from the tar package on to user home directory & link the lib folder location. Here is what you need to do
This will install Nodejs under ~/.local/ instead of the default /usr/local/
If you still encounter ownership or permission error while installing packages, then change ownership of ~/.local/ dir by running
Now you should be good to install packages via 'npm'
Note: ALL OF THE ABOVE COMMANDS ARE TO BE RUN AS USER. DO NOT USE SUDO OR ROOT LOGIN
NEVER EVER CHANGE THE PERMISSION OF FOLDERS UNDER '/USR/LIB/'. WILL LEAD TO UNSTABLE OS
Ubuntu 12.04 and using Chris Lea's PPA for install the following works for me:
and adding $HOME/.npm-packages/bin to $PATH
append to
.bashrc
see https://stackoverflow.com/a/18277225 from @passy