首页 > 解决方案 > 无法在 Ubuntu 20.04 上安装 json-server

问题描述

我正在尝试安装json-server但一再失败,这让我感到绝望。现在需要帮助来解决问题。在我在 Ubunto-20.04 操作系统上使用的命令下方。

  1. 安装的Nodejs版本: v14.16.0
  2. 安装的 NPM 版本: 6.14.10

虽然首先,我使用了15x的最新版本的 nodejs,但我也遇到了安装错误json-server,下面的命令用于安装json-server

  1. npm install json-server -g
  2. npm install -g json-server
  3. npm i json-server

我已使用上述所有命令进行安装json-server,但在每时每刻我都遇到错误,如下所示,

这是错误

checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
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! 
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/imdadul/.npm/_logs/2021-03-18T04_32_41_181Z-debug.log

注意:附加文件中也添加了错误,高级感谢您的帮助。 在此处输入图像描述

标签: javascriptjsonreactjsnpm

解决方案


您可以尝试使用 sudo,例如“sudo npm install -g json-server”,或者使用“chmod -r 777 /usr/local/lib/node_modules”授予写入权限。我认为 sudo 选项更适合即时许可。


推荐阅读