【问题标题】:npm permission issue on fresh install of Homestead / Vagrant / Laravel全新安装 Homestead / Vagrant / Laravel 的 npm 权限问题
【发布时间】:2018-10-15 12:31:54
【问题描述】:

用两天时间处理这个问题,结果成功了。

我有一个全新安装的Windows 10 主机,运行最新版本的Vagrant、laravel/homestead (Ubuntu 18.04 LTS box, v 6.0.0)、Virtualbox、laravel、git for windows、node.js for windows。

vagrant、git、virtualbox 设置为在windows 中以管理员身份运行。

我创建了一个名为 blog 的 Laravel 项目,如下所示:

vagrant@homestead:~/src$ composer create-project --prefer-dist laravel/laravel blog

一切正常。然后我尝试像这样安装npm:

vagrant@homestead:~/src/blog$ npm install -g npm@latest

我得到:

npm WARN checkPermissions Missing write access to /usr/lib/node_modules/npm
npm WARN checkPermissions Missing write access to /usr/lib/node_modules
npm ERR! path /usr/lib/node_modules/npm
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules/npm'
npm ERR!  { Error: EACCES: permission denied, access '/usr/lib/node_modules/npm'
npm ERR!   stack: 'Error: EACCES: permission denied, access \'/usr/lib/node_modules/npm\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/lib/node_modules/npm' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vagrant/.npm/_logs/2018-05-05T00_57_41_110Z-debug.log

但是当我检查vagrant 用户权限时:

vagrant@homestead:~/src/blog$ groups
vagrant adm cdrom sudo dip www-data plugdev lxd lpadmin sambashare

所以我用npm 不推荐的消息解决了这个问题:

vagrant@homestead:~/src/blog$ sudo npm install -g npm@latest

我现在去安装一个npm 包,比如highcharts:

vagrant@homestead:~/src/blog$ npm install --save highcharts
npm WARN rollback Rolling back highcharts@6.1.0 failed (this is probably harmless): ETXTBSY: text file is busy, unlink '/home/vagrant/src/blog/node_modules/highcharts/package.json.2262439515'
npm ERR! path /home/vagrant/src/blog/node_modules/highcharts/package.json.2262439515
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename
npm ERR! ETXTBSY: text file is busy, rename '/home/vagrant/src/blog/node_modules/highcharts/package.json.2262439515' -> '/home/vagrant/src/blog/node_modules/highcharts/package.json'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vagrant/.npm/_logs/2018-05-05T01_10_24_241Z-debug.log

我尝试 sudo 安装包,结果相同

vagrant@homestead:~/src/blog$ sudo npm install --save --no-bin-links highcharts 
npm WARN rollback Rolling back highcharts@6.1.0 failed (this is probably harmless): ETXTBSY: text file is busy, unlink '/home/vagrant/src/blog/node_modules/highcharts/package.json.1984492036'
npm ERR! path /home/vagrant/src/blog/node_modules/highcharts/package.json.1984492036
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename
npm ERR! ETXTBSY: text file is busy, rename '/home/vagrant/src/blog/node_modules/highcharts/package.json.1984492036' -> '/home/vagrant/src/blog/node_modules/highcharts/package.json'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vagrant/.npm/_logs/2018-05-05T01_58_13_140Z-debug.log

结果是node_modules 中的highchatrts 文件夹,其中只有packaje.json.1984492036 文件。

我似乎找不到解决办法。使用 --no-bin-links 会出现同样的错误。

感谢任何帮助。

【问题讨论】:

标签: laravel npm vagrant


【解决方案1】:

我通过从git 主机操作系统而不是从ubuntu vm 运行npm install 来完成所有工作。不是我想要的,但我向前迈进并学到了一些东西,并且越来越接近精神错乱......

【讨论】:

    【解决方案2】:

    两天前我遇到了同样的问题,尝试运行 sudo npm install --unsafe-perm ,但先撤消您所做的任何更改,因为我不知道代客是如何工作的(悲伤的 Linux 用户)

    【讨论】:

    • 感谢您的建议。我刚试过sudo npm install --unsafe-perm highcharts,结果一样,一模一样。
    • np,不客气,对不起,我不清楚,我的意思是使用 --unsafe-perm 运行命令来安装 npm 本身,但显然你已经解决了这个问题,嗯……你有吗尝试按照消息说的做(重命名 package.json),最好删除整个 node_modules 文件夹
    • 我有。令人费解的是,这一切都是新鲜的。因此,当我按照Laravel 安装说明执行npm install 时,会创建文件夹结构,并且对于每个包,我都会得到每个包含package.json.123124321 文件的空文件夹。 npm 由vagrant 用户运行,它似乎无权重命名此文件。然而它可以创建文件夹。 composer 也被vagrant 使用,创建项目没有问题。 #殴打
    猜你喜欢
    • 2016-12-07
    • 2015-09-14
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 2016-05-21
    • 2017-07-20
    • 2016-06-15
    相关资源
    最近更新 更多