Resolve EACCES permissions errors
Jul 10, 2018 · 2 分钟阅读

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

npx: an alternative to running global commands

If you are using npm version 5.2 or greater, you may want to consider npx as an alternative way to run global commands, especially if you only need a command occasionally. For more information, see this article about npx.

← Previous Post Next Post →

Ryun的博客
与其感慨路难行,不如马上出发。

atom css design git html javascript jekyll laravel life mac mobile optimization sublime tool vscode vue
mac

About

你好,❤朋友

这里是 Ryun 的博客 📝

📝记录了我学习 🔎的过程

作为一名前端攻城狮 🦁

希望能和大家一起 🔎

共同进步 🏃

🦁的特长:

  • HTML5
  • CSS3
  • JavaScript
  • Vue.js
  • 微信小程序
  • 熟练配合 Node.js、PHP 和 Laravel
  • 熟练使用各种开发和设计工具

🦁喜欢 🆒🆒的东西

对提升效率和美感的事物有兴趣 😋

欢迎 👏交流


see this hugo-theme-dream-ink