node.js npm install -g less 不起作用:EACCES:权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33725639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
npm install -g less does not work: EACCES: permission denied
提问by xslibx
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
我正在尝试在 phpstorm 上设置 less,这样我就可以在保存时将 .less 文件编译为 .css。我已经安装了 node.js,下一步(根据这个https://www.jetbrains.com/webstorm/help/transpiling-sass-less-and-scss-to-css.html)正在运行这个命令终端
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
└─┬ [email protected]
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
└── [email protected]
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!
我在这里完全是个菜鸟,不知道下一步该做什么。任何帮助将不胜感激!
回答by Vincent Gerris
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
不建议使用 sudo。它可能会在以后给你权限问题。虽然上述方法有效,但我不喜欢将 root 拥有的文件夹更改为可供用户写入,尽管这可能只是多个用户的问题。要解决这个问题,您可以使用一个带有“npm 用户”的组,但这也会带来更多的管理开销。有关处理文档中权限的选项,请参见此处:https: //docs.npmjs.com/getting-started/fixing-npm-permissions
I would go for option 2:
我会选择选项 2:
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-globalConfigure npm to use the new directory path:
npm config set prefix '~/.npm-global'Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATHBack on the command line, update your system variables:
source ~/.profileTest: Download a package globally without using sudo.
npm install -g jshintIf still show permission error run (mac os):
sudo chown -R $USER ~/.npm-global
为了最大限度地减少权限错误的可能性,您可以将 npm 配置为使用不同的目录。在本例中,它将是您的主文件夹中的一个隐藏目录。
为全局安装创建一个目录:
mkdir ~/.npm-global配置 npm 以使用新的目录路径:
npm config set prefix '~/.npm-global'打开或创建一个 ~/.profile 文件并添加以下行:
export PATH=~/.npm-global/bin:$PATH回到命令行,更新您的系统变量:
source ~/.profile测试:不使用 sudo 全局下载包。
npm install -g jshint如果仍然显示权限错误运行(mac os):
sudo chown -R $USER ~/.npm-global
This works with the default ubuntu install of:
这适用于默认的 ubuntu 安装:
sudo apt-get install nodejs npm
I recommend nvmif you want more flexibility in managing versions:
https://github.com/creationix/nvm
nvm如果您想更灵活地管理版本,我建议您:https:
//github.com/creationix/nvm
On MacOS use brew, it should work without sudoout of the box if you're on a recent npmversion.
Enjoy :)
在 MacOS 上使用 brew,sudo如果您使用的是最新npm版本,它应该可以在没有开箱即用的情况下工作。享受 :)
回答by Vagner Rodrigues
Run these commands in a terminal window (note: DON'T replace the $USER part... thats a linux command to get your user!):
在终端窗口中运行这些命令(注意:不要替换 $USER 部分...这是获取用户的 linux 命令!):
sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules
回答by gazdagergo
Reinstall node and npm with Node Version Manger(as per written in npm documentation) to avoid permission errors:
使用Node Version Manger重新安装 node 和 npm (如npm 文档中所述)以避免权限错误:
In OSX:
在 OSX 中:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
or follow this article:
或关注这篇文章:
http://dev.topheman.com/install-nvm-with-homebrew-to-use-multiple-versions-of-node-and-iojs-easily/
http://dev.topheman.com/install-nvm-with-homebrew-to-use-multiple-versions-of-node-and-iojs-easily/
Windows users should install nvm-windows. For further help how to install nvm refer the nvm readme.
Windows 用户应该安装nvm-windows。有关如何安装 nvm 的进一步帮助,请参阅nvm 自述文件。
Then choose for example:
然后选择例如:
nvm install 8.0.0
nvm use 8.0
Now you can give another try:
现在你可以再试一次:
npm install -g less
回答by Roderick Jonsson
Mac OS X Answer
Mac OS X 答案
You don't have write access to the node_modules directory
您没有对 node_modules 目录的写访问权限
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
Add your User to the directory with write access
将您的用户添加到具有写访问权限的目录中
回答by Asadut Zaman
For my mac environment
对于我的 mac 环境
sudo chown -R $USER /usr/local/lib/node_modules
solve the issue
解决问题
回答by user3393929
回答by Akash Singh Sengar
Just Hit below command :
只需点击以下命令:
sudo chown -R $USER /usr/local/lib/node_modules
Let's break it down:
让我们分解一下:
sudo
须藤
means we are running this command as root, the system super user. This is because we don't have permission to write to that folder, but root will be able to fix any permission. This command also means the system will ask for your password to confirm.
意味着我们以 root 用户身份运行此命令,系统超级用户。这是因为我们没有写入该文件夹的权限,但 root 将能够修复任何权限。此命令也意味着系统将要求您输入密码以进行确认。
chown
chown
is the command we use to change the owner of a file or folder. We set the -R option to change the owner recursively, so we also get owner access to all the files already contained in there.
是我们用来更改文件或文件夹所有者的命令。我们设置 -R 选项以递归方式更改所有者,因此我们还可以获得对已包含在其中的所有文件的所有者访问权限。
$USER
$USER
is an environment variable automatically set to your username.
是一个自动设置为您的用户名的环境变量。
And the final piece is the folder path.
最后一部分是文件夹路径。
Running this path will make the folder yours, so you can safely run your npm install -g commands!
运行此路径将使文件夹成为您的文件夹,因此您可以安全地运行 npm install -g 命令!
回答by Gohar SUltan
I have tried all the suggested solutions but nothing worked.
我已经尝试了所有建议的解决方案,但没有任何效果。
I am using macOS Catalina 10.15.3
我使用的是 macOS Catalina 10.15.3
Go to /usr/local/
转到 /usr/local/
Select bin folder > Get Info
选择 bin 文件夹 > 获取信息
Add your user to Sharing & Permissions.
Read & Write Permissions.

And go to terminal and run npm install -g @ionic/cli
并转到终端并运行 npm install -g @ionic/cli
It has helped me.
它帮助了我。
回答by kira
In linux make sure getting all authority with:
在 linux 中,确保获得所有权限:
sudo su
回答by Jim
Another option is to download and install a new version using an installer.
另一种选择是使用安装程序下载并安装新版本。

