Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I was trying to install npm, and I got

npm ERR! Error: EACCES, Permission denied '/usr/local/lib/node_modules'
npm ERR! 
npm ERR! Please use 'sudo' or log in as root to run this command.
npm ERR! 
npm ERR!     sudo npm "install" "." "--force" "--global"
npm ERR! 
npm ERR! or set the 'unsafe-perm' config var to true.
npm ERR! 
npm ERR!     npm config set unsafe-perm true

How can log in as a root?

share|improve this question
    
Do not login as root. ;-) –  Chris Page Apr 6 '12 at 13:14
add comment

3 Answers 3

up vote 17 down vote accepted

sudo -s is far easier than enabling the root user since it just starts up a shell with root permissions as a one step, on demand action. Not only is it fast, but it doesn't need to be reconfigured when you don't need the root user and doesn't expose the server to any more risk or vulnerability that adding a root user would entail.

share|improve this answer
6  
But better to sudo the one command rather than run under a shell as root –  Mark Jun 19 '11 at 20:52
    
Could you explain what sudo -s does in this context? –  KatieK Jul 31 '13 at 19:51
    
@KatieK The command sudo -s runs a shell as root. The manual page has these details and much more. I will add some words since your question is a good one and many others might also wonder what it does. –  bmike Jul 31 '13 at 20:22
    
@bmike - That's exactly what I needed - thanks! –  KatieK Jul 31 '13 at 23:12
add comment

You need to use the su (switch user) command to become root, but only root is allowed to become root, so you need to use sudo (super-user do). Therefore, type: sudo su.

[william@NCC-1701 ~]$ sudo su
Password:
[root@NCC-1701 /Users/william]$ 

If you haven't used root before, you should be made fully aware that one wrong character typed as root will delete your entire operating system, including your photos, emails and financial documents. Be extremely careful and always triple-read what you type before hitting enter. Otherwise, good luck!

share|improve this answer
1  
been an AIX support technician for 3 years ... 12 years ago :) know some stuff but the simple stuff had vanished from my head :) –  balexandre May 18 '11 at 18:51
    
I was going to snark my answer with friendly manual and google suggestions but quickly deleted it after reading your bio. Welcome to mac. I still can't bring myself to type vm_stat after years of AIX. Gotta love shell aliases ;-) –  bmike May 18 '11 at 19:15
    
Why use sudo su instead of sudo -s? –  Chris Page Apr 6 '12 at 13:13
1  
All I see is NCC-1701 lol –  Shane Hsu Nov 18 '13 at 10:52
add comment

I usually do it bit differently than how others described here. Lets imagine you have two users. standard user: john admin user: kevin

If john is logged in and wants to run as a root user(as kevin) here is how I do it.

su kevin

when asked enter kevin's password

sudo npm "install" "." "--force" "--global"

enter kevin's password again.

share|improve this answer
    
After you've already switched user to kevin, why do you need the sudo? –  cm2 Jan 16 '12 at 17:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.