zoukankan      html  css  js  c++  java
  • Resolving EACCES permissions errors when installing packages globally(npm 遇到 write access的问题)

    If you see an EACCES error when you try to install a package globally, you can either:

    • Reinstall npm with a node version manager (recommended),

    or

    • Manually change npm’s default directory

    Reinstall npm with a node version manager§

    This is the best way to avoid permissions issues. To reinstall npm with a node version manager, follow the steps in “Downloading and installing Node.js and npm”. You do not need to remove your current version of npm or Node.js before installing a node version manager.

    Manually change npm’s default directory§

    Note: This section does not apply to Microsoft Windows.

    To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory.

    1. Back up your computer.
    2. On the command line, in your home directory, create a directory for global installations:
       mkdir ~/.npm-global
      
    3. Configure npm to use the new directory path:
       npm config set prefix '~/.npm-global'
      
    4. In your preferred text editor, open or create a ~/.profile file and add this line:
       export PATH=~/.npm-global/bin:$PATH
      
    5. On the command line, update your system variables:
       source ~/.profile
      
    6. To test your new configuration, install a package globally without using sudo:
       npm install -g jshint
      

    Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don’t want to modify ~/.profile):

    NPM_CONFIG_PREFIX=~/.npm-global
     
    # 第一步:在你的用户文件下新建一个文件夹,这个.npm-global 名字可以用你自己喜欢的名字替换,推荐直接使用这个名字。
    mkdir ~/.npm-global
    #第二步:更改node的安装连接
    npm config set prefix '~/.npm-global'
    #第三步:在用户的profile下增加path,为的是系统能够找到可执行文件的目录
     export PATH=~/.npm-global/bin:$PATH
    #第四步:update profile。使其生效
    source ~/.profile



  • 相关阅读:
    生成器 三元表达式 列表生成式 匿名函数 内置函数
    迭代器
    叠加装饰器和补充部分
    函数的名称空间和作用域
    函数基础
    闭包函数和装饰器
    文件的处理
    第十章 程序的循环结构
    第九章 身体质量指数BMI的python实现
    第八章 程序的分支结构
  • 原文地址:https://www.cnblogs.com/landv/p/10897770.html
Copyright © 2011-2022 走看看