【问题标题】:Where to permanently set npm proxy?在哪里永久设置 npm 代理?
【发布时间】:2017-01-13 13:44:09
【问题描述】:

在使用 npm 时设置代理我使用:

npm config set proxy http://proxy.pro.com:8080
npm config set https-proxy http://proxy.pro.com:8080

我在 mac 终端中每次使用 npm 时都设置了这个。应该在哪里添加此命令以永久设置代理,以便所有终端实例都可以使用?

我可以在 mac 启动时运行启动脚本,但如何确保代理配置可用于所有终端实例?

【问题讨论】:

    标签: macos terminal npm


    【解决方案1】:

    您可以创建一个 .npmrc 文件并将配置放入其中

    proxy http://proxy.pro.com:8080
    https-proxy http://proxy.pro.com:8080
    

    【讨论】:

    • 这应该是公认的答案! FWIW,Windows 中的默认 npmrc 位置:C:\Users\%username%\AppData\Roaming\npm\etc\npmrc。检查它是否应用:npm config edit.
    【解决方案2】:
    npm config set https-proxy https://username:pwd@proxy.company.com:8080
    
    npm config set proxy https://username:pwd@proxy.company.com:8080
    
    npm config set sslVerify false
    
    npm config set strict-ssl false
    
    set HTTP_PROXY=http://username:pwd@proxy.company.com:8080
    
    set HTTPS_PROXY=https://username:pwd@proxy.company.com:8080
    

    永久设置代理:

    HTTP_PROXYHTTPS_PROXY添加到系统环境变量中

    【讨论】:

      【解决方案3】:

      您可以将它放在您的bash 配置文件或其他shell 启动脚本中。所以,例如$HOME/.profile

      如果您的意思是,“所有用户的所有终端实例”,那么您需要将其放入 /etc/bashrc

      【讨论】:

        猜你喜欢
        • 2013-03-26
        • 2020-12-12
        • 2011-05-17
        • 1970-01-01
        • 2023-01-23
        • 1970-01-01
        • 2023-02-04
        • 2011-11-25
        • 1970-01-01
        相关资源
        最近更新 更多