Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Error when installing http-server npm package. Permission denied.

Here's the error I get when I try and install http-server globally. I was using the link provided in the teacher notes for instructions on http-server. Any help? I am a beginner with the terminal and I am uncomfortable taking chances here.

Mindys-MBP:~ mindysandilands1$ npm install http-server -g npm ERR! tar.unpack untar error /Users/mindysandilands1/.npm/http-server/0.9.0/package.tgz npm ERR! Darwin 14.5.0 npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "http-server" "-g" npm ERR! node v4.4.5 npm ERR! npm v2.15.5 npm ERR! path /usr/local/lib/node_modules/http-server npm ERR! code EACCES npm ERR! errno -13 npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/http-server' npm ERR! at Error (native) npm ERR! { [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/http-server'] npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'mkdir', npm ERR! path: '/usr/local/lib/node_modules/http-server', npm ERR! fstream_type: 'Directory', npm ERR! fstream_path: '/usr/local/lib/node_modules/http-server', npm ERR! fstream_class: 'DirWriter', npm ERR! fstream_stack: npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:35:25', npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53', npm ERR! 'FSReqWrap.oncomplete (fs.js:82:15)' ] } npm ERR! npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request: npm ERR! /Users/mindysandilands1/npm-debug.log

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Mindy,

You simply need to run the npm command as sudo as the default location for NodeJS packages on OS X is protected by the admin group.

sudo npm install http-server -g

You will just need to enter your account password but after that, the installation of http-server will succeed.

Happy coding!

Thanks a bunch. That worked perfect.

Routine Poutine
Routine Poutine
26,050 Points

Thanks! I didn't realize the permission required was mine. haha.

Go to your lib folder and assign full permissions, you can do it through the terminal by writing chmod 777, remember to go to the folder before you run that command

Chris Shaw
Chris Shaw
26,676 Points

As mentioned in my reply below, this error is caused by group level folder permissions that restrict users from writing to it. It is highly recommended not changing permissions to system folders as it can create system level vulnerabilities.