npm install -g less 不起作用:EACCES:权限被拒绝 [英] npm install -g less does not work: EACCES: permission denied
问题描述
我正在尝试在 phpstorm 上设置 less,以便我可以在保存时将 .less 文件编译为 .css.我已经安装了 node.js 和下一步(根据这个 https://www.jetbrains.com/webstorm/help/transpiling-sass-less-and-scss-to-css.html) 正在终端中运行此命令
I'm trying to set up less on phpstorm so I can compile .less files to .css on save. I have installed node.js and the next step (according to this https://www.jetbrains.com/webstorm/help/transpiling-sass-less-and-scss-to-css.html) is running this command in the terminal
npm install -g less
然而,当我这样做时,我得到了这些错误
However when I do this I get these errors
☁ ~ npm install -g less
npm WARN install Couldn't install optional dependency: EACCES: permission denied, mkdir '/Users/brentscholl/.npm/mkdirp/0.5.1'
npm WARN install Couldn't install optional dependency: EACCES: permission denied, mkdir '/Users/brentscholl/.npm/graceful-fs/3.0.8'
npm WARN install Couldn't install optional dependency: EACCES: permission denied, mkdir '/Users/brentscholl/.npm/extend/3.0.0'
npm WARN install Couldn't install optional dependency: EACCES: permission denied, mkdir '/Users/brentscholl/.npm/readable-stream/2.0.4'
npm WARN install Couldn't install optional dependency: EACCES: permission denied, mkdir '/Users/brentscholl/.npm/chalk/1.1.1'
npm WARN install Couldn't install optional dependency: EACCES: permission denied, mkdir '/Users/brentscholl/.npm/xtend/4.0.1'
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
/usr/local/lib
└─┬ less@2.5.3
├─┬ errno@0.1.4
│ └── prr@0.0.0
├── image-size@0.3.5
├── mime@1.3.4
├─┬ promise@6.1.0
│ └── asap@1.0.0
└─┬ source-map@0.4.4
└── amdefine@1.0.0
npm ERR! Darwin 15.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "less"
npm ERR! node v5.0.0
npm ERR! npm v3.3.6
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! at Error (native)
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
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/brentscholl/npm-debug.log
我在这里完全是个菜鸟,不知道接下来要做什么.任何帮助将不胜感激!
I'm a complete noob here and not sure what to do next. Any help would be very appreciated!
推荐答案
不推荐使用 sudo.它可能会在以后给你权限问题.虽然上述方法有效,但我不喜欢将 root 拥有的文件夹更改为可供用户写入,尽管这可能只是多个用户的问题.要解决这个问题,您可以使用一个带有npm 用户"的组,但这也是更多的管理开销.有关处理文档中权限的选项,请参见此处:https://docs.npmjs.com/getting-started/fixing-npm-permissions
Using sudo is not recommended. It may give you permission issue later. While the above works, I am not a fan of changing folders owned by root to be writable for users, although it may only be an issue with multiple users. To work around that, you could use a group, with 'npm users' but that is also more administrative overhead. See here for the options to deal with permissions from the documentation: https://docs.npmjs.com/getting-started/fixing-npm-permissions
我会选择选项 2:
为了尽量减少权限错误的机会,您可以将 npm 配置为使用不同的目录.在这个例子中,它将是一个隐藏的主文件夹中的目录.
To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, it will be a hidden directory on your home folder.
为全局安装创建一个目录:
Make a directory for global installations:
mkdir ~/.npm-global
配置 npm 以使用新的目录路径:
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
打开或创建一个 ~/.profile 文件并添加这一行:
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
回到命令行,更新你的系统变量:
Back on the command line, update your system variables:
source ~/.profile
测试:不使用 sudo 全局下载包.
Test: Download a package globally without using sudo.
npm install -g jshint
如果仍然显示权限错误运行(mac os):
If still show permission error run (mac os):
sudo chown -R $USER ~/.npm-global
这适用于默认的 ubuntu 安装:
This works with the default ubuntu install of:
sudo apt-get install nodejs npm
如果您希望在管理版本方面具有更大的灵活性,我推荐 nvm
:https://github.com/creationix/nvm
I recommend nvm
if you want more flexibility in managing versions:
https://github.com/creationix/nvm
在 MacOS 上使用 brew,如果您使用的是最近的 npm
版本,它应该可以在没有 sudo
开箱即用的情况下工作.享受:)
On MacOS use brew, it should work without sudo
out of the box if you're on a recent npm
version.
Enjoy :)
这篇关于npm install -g less 不起作用:EACCES:权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!