Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c1b9ca

Browse files
authored
docs: improve documentation on resolving EACCES (#1711)
Simplify the steps a bit: - Backing up the computer and creating the directory is not necessary, since it's created automatically by npm. - Use the ~/.local directory which is the standard place for user-specific software, and likely to already be in the user's PATH. - `export` is not needed since PATH is already exported. - Add a note for zsh which doesn't use ~/.profile. - Use a different package as an example, since jshint is not regularly updated, and linters should generally be in `devDependencies` and used through npm scripts. - Ensure the user can run the installed tool. - Remove mention of `NPM_CONFIG_PREFIX` which is not sufficient, since the PATH still needs to be updated to use global tools.
1 parent ae95f55 commit 8c1b9ca

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

content/packages-and-modules/getting-packages-from-the-registry/resolving-eacces-permissions-errors-when-installing-packages-globally.mdx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,43 @@ This is the best way to avoid permissions issues. To reinstall npm with a node v
2424

2525
</Note>
2626

27-
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.
27+
To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use a hidden directory in your home directory.
2828

29-
1. Back up your computer.
30-
31-
2. On the command line, in your home directory, create a directory for global installations:
29+
1. Configure npm to use the new directory path:
3230

3331
```
34-
mkdir -p ~/.npm-global/lib
32+
npm config set prefix ~/.local
3533
```
3634

37-
3. Configure npm to use the new directory path:
35+
2. In your preferred text editor, open or create a `~/.profile` file and add this line:
3836

3937
```
40-
npm config set prefix ~/.npm-global
38+
PATH=~/.local/bin:$PATH
4139
```
4240

43-
4. In your preferred text editor, open or create a `~/.profile` file and add this line:
41+
If you are using zsh (which you can find out by running `echo $0`), you will also need to add this line to `~/.zprofile`:
4442

4543
```
46-
export PATH=~/.npm-global/bin:$PATH
44+
source ~/.profile
4745
```
4846

49-
5. On the command line, update your system variables:
47+
3. On the command line, update your system variables:
5048

5149
```
5250
source ~/.profile
5351
```
5452

55-
6. To test your new configuration, install a package globally without using `sudo`:
53+
4. To test your new configuration, install a package globally without using `sudo`:
5654

5755
```
58-
npm install -g jshint
56+
npm install -g npm-check-updates
5957
```
6058

61-
Instead of steps 3-5, you can use the corresponding ENV variable (e.g. if you don't want to modify `~/.profile`):
59+
And run it:
6260

63-
```
64-
NPM_CONFIG_PREFIX=~/.npm-global
65-
```
61+
```
62+
ncu -g
63+
```
6664

6765
<Note>
6866

0 commit comments

Comments
 (0)