How to fix the "Missing write access" error when using npm 报错

 

 


The first time you try to install a package globally using npm, using the syntax npm install -g <package> on a Mac, or Linux, you might get a weird error, saying something like

Missing write access to /usr/local/lib/node_modules

 

baocuo

or something along those lines, followed by a long list of other errors of warnings, a consequence of the first error that’s printed to you.

This error is preventing us to install the package.

How do you fix this? It’s a permission error, which means you don’t have write access to that folder.

This is how to solve it. Run this 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.

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.

$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 <package> commands!

Pay attention to the folder listed by the error message. If it’s different, update the chown command accordingly.

 

或类似的内容,然后是一长串其他警告错误,这是打印到您的第一个错误的结果。

 

此错误使我们无法安装软件包。

 

您如何解决这个问题?这是一个权限错误,这意味着您没有对该文件夹的写权限。

 

这是解决方法。运行以下命令:

 

sudo chown -R $USER /usr/local/lib/node_modules

让我们分解一下:

 

sudo表示我们root以系统超级用户身份运行此命令。这是因为我们没有写该文件夹的权限,但是root可以修复任何权限。此命令还意味着系统将要求您输入密码以进行确认。

 

chown是用于更改文件或文件夹所有者的命令。我们设置了-R以递归方式更改所有者的选项,因此我们还可以使所有者访问其中已经包含的所有文件。

 

$USER 是自动设置为您的用户名的环境变量。

 

最后一块是文件夹路径。

 

运行此路径将使该文件夹成为您的文件夹,因此您可以安全地运行npm install -g <package>命令!

 

请注意错误消息列出的文件夹。如果不同,请相应地更新chown命令

 

 

 

或类似的内容,然后是一长串其他警告错误,这是打印到您的第一个错误的结果。

此错误使我们无法安装软件包。

您如何解决这个问题?这是一个权限错误,这意味着您没有对该文件夹的写权限。

这是解决方法。运行以下命令:

让我们分解一下:

sudo表示我们root以系统超级用户身份运行此命令。这是因为我们没有写该文件夹的权限,但是root可以修复任何权限。此命令还意味着系统将要求您输入密码以进行确认。

chown是用于更改文件或文件夹所有者的命令。我们设置了-R以递归方式更改所有者的选项,因此我们还可以使所有者访问其中已经包含的所有文件。

$USER 是自动设置为您的用户名的环境变量。

最后一块是文件夹路径。

运行此路径将使该文件夹成为的文件夹,因此您可以安全地运行npm install -g <package>命令!

请注意错误消息列出的文件夹。如果不同,请相应地更新chown命令

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值