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.

Mohamed Akram committed Sep 16, 2025 at 00:11 UTC 8c1b9cacc17bfa6b96b0ecd722d6759c3e7b9021
1 file changed +14 -16
content/packages-and-modules/getting-packages-from-the-registry/resolving-eacces-permissions-errors-when-installing-packages-globally.mdx
+14 -16
@@ -24,45 +24,43 @@ This is the best way to avoid permissions issues. To reinstall npm with a node v
24
25 </Note>
26
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.
28
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:
30
31 ```
34 - mkdir -p ~/.npm-global/lib
32 + npm config set prefix ~/.local
33 ```
34
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:
36
37 ```
40 - npm config set prefix ~/.npm-global
38 + PATH=~/.local/bin:$PATH
39 ```
40
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`:
42
43 ```
46 - export PATH=~/.npm-global/bin:$PATH
44 + source ~/.profile
45 ```
46
49 -5. On the command line, update your system variables:
47 +3. On the command line, update your system variables:
48
49 ```
50 source ~/.profile
51 ```
52
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`:
54
55 ```
58 - npm install -g jshint
56 + npm install -g npm-check-updates
57 ```
58
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:
60
63 -```
64 -NPM_CONFIG_PREFIX=~/.npm-global
65 -```
61 + ```
62 + ncu -g
63 + ```
64
65 <Note>
66