NodeJS 我在全球安装cowsay软件包时遇到了这个问题,我该如何解决它?

yjghlzjz  于 2023-01-08  发布在  Node.js
关注(0)|答案(2)|浏览(218)

我曾尝试在npm的帮助下全局安装cowsay包,但遇到以下错误。

npm i -g考赛

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
        npm ERR! code EACCES
        npm ERR! syscall mkdir
        npm ERR! path /usr/local/lib/node_modules/cowsay
        npm ERR! errno -13
        npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/cowsay'
        npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/cowsay'] {
        npm ERR!   errno: -13,
        npm ERR!   code: 'EACCES',
        npm ERR!   syscall: 'mkdir',
        npm ERR!   path: '/usr/local/lib/node_modules/cowsay'
        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.
toe95027

toe950271#

要获取目录及其所有者的列表:

ls -l

找到npm安装到的文件夹,更改用户的所有权权限。您可以通过以下方法完成此操作:

sudo chown <user_id> <folder_name>

这会将给定文件夹的所有者权限更改为您的用户。现在npm应该可以安装了。

jrcvhitl

jrcvhitl2#

粘贴以下命令并运行:

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

然后运行原始命令:

npm i -g cowsay

相关问题