ubuntu 上的 Expo CLI 问题

Expo CLI issue on ubuntu

我已经在我的根目录下 ubuntu 20.04 下载了 expo cli,但我无法全局下载它! 我希望 expo cli 在全球范围内存在,因为不建议通过根目录打开代码编辑器。

这是我的终端显示的内容!

npm ERR! code EACCES
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/yarn/bin/yarn.js
npm ERR! dest /usr/local/bin/yarn
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/yarn/bin/yarn.js' -> '/usr/local/bin/yarn'
npm ERR!  { [Error: EACCES: permission denied, symlink '../lib/node_modules/yarn/bin/yarn.js' -> '/usr/local/bin/yarn']
npm ERR!   cause:
npm ERR!    { Error: EACCES: permission denied, symlink '../lib/node_modules/yarn/bin/yarn.js' -> '/usr/local/bin/yarn'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'symlink',
npm ERR!      path: '../lib/node_modules/yarn/bin/yarn.js',
npm ERR!      dest: '/usr/local/bin/yarn' },
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, symlink \'../lib/node_modules/yarn/bin/yarn.js\' -> \'/usr/local/bin/yarn\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '../lib/node_modules/yarn/bin/yarn.js',
npm ERR!   dest: '/usr/local/bin/yarn' }
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/ritik/.npm/_logs/2020-07-03T19_44_34_737Z-debug.log

这是权限问题。你可以使用 sudo 来解决这个问题,但作为一般建议,永远不要 运行 npm installsudo 因为这通常是一个坏主意,你可以阅读更多关于这个 here

因此,为了尽量减少此问题,您可以将 npm 配置为使用不同的目录进行全局包安装,如 npm docs here

中所述
  1. 在命令行中,在您的主目录中,为全局安装创建一个目录:

    mkdir ~/.npm-global
    
  2. 配置 npm 以使用新的目录路径:

    npm config set prefix '~/.npm-global'
    
  3. 在您首选的文本编辑器中,打开或创建一个 ~/.profile 文件并添加以下行:

    export PATH=~/.npm-global/bin:$PATH
    
  4. 在命令行中,更新您的系统变量:

    source ~/.profile
    
  5. 最后尝试全局安装 expo-cli :

    npm install -g expo-cli 
    

或者如果你想要一个快速修复,你可以试试这个

  1. 打开一个终端然后运行:

    sudo chown -R $USER:$USER /usr/local/lib/node_modules
    
  2. 尝试安装 expo-cli ,运行 :

     npm i -g expo-cli  
    

另外 考虑避免全局安装并尽可能使用 npx 阅读更多 here