Skip to content
CoursesWeb Forum

npm install fails with EACCES permission denied on Linux

Asked by Bertie H. · Node.js and Server Side JavaScript2 repliesupdated

Short answer

Debian box, Node from the distro package, normal user. I want a small static server for testing and run:

Written by Bertie H. ·
CiteCoursesWeb Forum, "npm install fails with EACCES permission denied on Linux", https://coursesweb.net/forum/t/npm-install-fails-with-eacces-permission-denied-on-linux/, accessed 2026-12-05.
  1. Member ·
    $ npm install -g http-server
    npm ERR! code EACCES
    npm ERR! syscall mkdir
    npm ERR! path /usr/lib/node_modules/http-server
    npm ERR! errno -13
    npm ERR! Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/http-server'
    npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/http-server'] {
    

    Obviously /usr/lib belongs to root. I can sudo it, but I have been burned by root owned files in my home directory before, and I do not like the idea of npm running install scripts as root.

    $ node -v
    v18.19.0
    $ npm -v
    9.2.0
    $ ls -ld /usr/lib/node_modules
    drwxr-xr-x 3 root root 4096 Oct 14 09:12 /usr/lib/node_modules
    

    What is the clean way to do global installs as a normal user? I would rather not change system directories at all. Terminal answers preferred.

    4
    ReplyLink

Plain text or simple Markdown. Links are nofollow. Your email is never shown.

  1. Zaid M.Member ·

    had this on my school pc. sudo chmod -R 777 /usr/lib/node_modules fixed it for me, then npm install works without sudo. i dont know what 777 means exactly but the error went away and the install finished

  2. Mpho N.Member ·

    Just use sudo npm install -g http-server. It is a global tool, so it makes sense that it goes into a root folder. Lecturers do this all the time. On my laptop with Ubuntu I always put sudo in front and never had a problem with the install itself.

CoursesWeb Forum. Questions and answers on learning web development: HTML, CSS, JavaScript, PHP, MySQL, Node.js and AI coding help.