npm install -g less不起作用:EACCES:权限被拒绝 [英] npm install -g less does not work: EACCES: permission denied
问题描述
我正在尝试在phpstorm上减少设置,以便在保存时将.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 users"一起使用,但这也增加了管理开销. 请参阅此处以获取处理文档中权限的选项: 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.
为全局安装创建目录:
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屋!