gpt4 book ai didi

shell - 错误 : EACCES: permission denied, 访问 '/usr/lib/node_modules'

转载 作者:行者123 更新时间:2023-12-02 00:08:57 26 4
gpt4 key购买 nike

我正在尝试使用命令 npm install -g typescript 安装 typescript,它返回此错误:

    npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Linux 4.4.0-93-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "typescript"
npm ERR! node v6.11.2
npm ERR! npm v3.10.10
npm ERR! path npm-debug.log.1024969454
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open

npm ERR! Error: EACCES: permission denied, open 'npm-debug.log.1024969454'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, open 'npm-debug.log.1024969454'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: 'npm-debug.log.1024969454' }
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! /npm-debug.log
jramirez@jramirez:/$ ^C
jramirez@jramirez:/$ npm install typescript
npm WARN checkPermissions Missing write access to /
/
└── typescript@2.5.2

npm WARN enoent ENOENT: no such file or directory, open '/package.json'
npm WARN !invalid#1 No description
npm WARN !invalid#1 No repository field.
npm WARN !invalid#1 No README data
npm WARN !invalid#1 No license field.
npm ERR! Linux 4.4.0-93-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "typescript"
npm ERR! node v6.11.2
npm ERR! npm v3.10.10
npm ERR! path /
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access

npm ERR! Error: EACCES: permission denied, access '/'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, access '/'
npm ERR! at Error (native) errno: -13, code: 'EACCES', syscall: 'access', path: '/' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Linux 4.4.0-93-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "typescript"
npm ERR! node v6.11.2
npm ERR! npm v3.10.10
npm ERR! path npm-debug.log.2387664261
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open

npm ERR! Error: EACCES: permission denied, open 'npm-debug.log.2387664261'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, open 'npm-debug.log.2387664261'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: 'npm-debug.log.2387664261' }
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! /npm-debug.log

此外,我运行npm install typescript(不带-g),但它不起作用。还有其他方式安装 typescript 吗?我的操作系统是Linux Ubuntu 16.04。我很少使用 node 并且不知道如何解决这个问题。

我的问题是:到底哪些目录需要该权限?

最佳答案

不建议在 npm install 中使用 sudo,而是按照 npmjs 官方文档中的步骤进行操作

为全局安装创建一个目录:

mkdir ~/.npm-global

配置 npm 使用新的目录路径:

npm config set prefix '~/.npm-global'

打开或创建 ~/.profile 文件并添加以下行:

export PATH=~/.npm-global/bin:$PATH

返回命令行,更新系统变量:

source ~/.profile

测试:不使用 sudo 全局下载包。

npm install -g typescript

来源:https://docs.npmjs.com/getting-started/fixing-npm-permissions

关于shell - 错误 : EACCES: permission denied, 访问 '/usr/lib/node_modules',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46058546/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com