I'm having trouble installing CoffeeScript using npm. When I try to install it globally, I get a permission denied error. Here's what I'm seeing:
$ npm install -g coffee-script
npm ERR! EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! Try running with sudo or get access to the local folder
My setup:
- Node.js: v14.17.0
- npm: 6.14.13
- OS: macOS Big Sur
I know using sudo isn't recommended, but I'm not sure how to fix this. Any ideas on how to change the permissions for /usr/local/lib safely? Or is there a better way to install CoffeeScript without running into these permission problems?
I've tried updating npm and Node.js, but the issue persists. Any help would be great!
I’ve been through this headache too and found a workaround that’s been a lifesaver. Instead of altering system permissions, I switched to using nvm, the Node Version Manager. I installed nvm following online guides and then installed Node.js version 14.17.0 with it. After switching to that version, I was able to install CoffeeScript globally without running into permissions issues. This method keeps installations within the user space and also offers the flexibility to manage multiple Node.js versions, which has greatly simplified my workflow.
hey mate, ran into this problem too. quick fix: try using npx
instead of installing globally. just run npx coffee-script
when u need it. no permission hassles, and u always get the latest version. worked like a charm for me!
I’ve encountered similar permission issues before, and I eventually discovered a safer solution that avoids using sudo. Instead of altering system-level directories, you can configure npm to use a directory within your home folder for global installations. Begin by creating a dedicated directory, then update npm’s configuration to point to this new location. After making sure that your PATH environment variable includes this directory, refresh your terminal session. This adjustment should let you install CoffeeScript globally without any permission errors.