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:如何防止权限错误的主要内容,如果未能解决你的问题,请参考以下文章