markdown NPM:如何防止权限错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown NPM:如何防止权限错误相关的知识,希望对你有一定的参考价值。

# NPM: How to Prevent Permissions Errors

This section does not apply to Microsoft Windows. This chapter will be updated to address Windows in the near future.

To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, it will be a hidden directory on your home folder.

Back-up your computer before you start.

Make a directory for global installations:
```bash
mkdir ~/.npm-global
```

Configure npm to use the new directory path:
```bash
npm config set prefix '~/.npm-global'
```

Open or create a `~/.profile` file and add this line:
```bash
export PATH=~/.npm-global/bin:$PATH
```
Back on the command line, update your system variables:
```bash
source ~/.profile
```

Test: Download a package globally without using sudo.
```bash
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`):
```bash
NPM_CONFIG_PREFIX=~/.npm-global
```

source: https://docs.npmjs.com/getting-started/fixing-npm-permissions

以上是关于markdown NPM:如何防止权限错误的主要内容,如果未能解决你的问题,请参考以下文章

如何防止 npm run lint 自动修复错误?

markdown npm错误#

markdown 安装npm install -g出现错误解决方法

markdown 修复NPM错误初始化Apollo GraphQL项目“未命名的项目”

npm 包无法安装“npm ERR!错误:EACCES:权限被拒绝”

升级 npm,npm ERR!错误:EACCES:权限被拒绝