Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rhand's avatar
Level 6

Laravel Forge NPM Permission Issues

I wanted to do a npm -g npm and when I did I hit errors such as

...
npm WARN checkPermissions Missing write access to /usr/lib/node_modules/npm/node_modules/archy
npm WARN checkPermissions Missing write access to /usr/lib/node_modules/npm/node_modules/columnify
...

Found out some directories / packages under forge are root:root

forge@app-staging:/usr/lib/node_modules/npm/node_modules$ ll
total 1440
drwxr-xr-x 358 root  root  12288 Feb  2  2021 ./
drwxr-xr-x   9 root  root   4096 Feb  2  2021 ../
drwxr-xr-x   2 root  root   4096 Feb  2  2021 .bin/
drwxr-xr-x   4 forge forge  4096 Feb  2  2021 JSONStream/
drwxr-xr-x   2 root  root   4096 Jun 19  2018 abbrev/
drwxr-xr-x   3 forge forge  4096 Feb  2  2021 agent-base/
drwxr-xr-x   3 forge forge  4096 Feb  2  2021 agentkeepalive/
drwxr-xr-x   2 forge forge  4096 Feb  2  2021 ansi-align/
drwxr-xr-x   2 forge forge  4096 Feb  2  2021 ansi-regex/
drwxr-xr-x   2 root  root   4096 Jun 19  2018 ansistyles/
drwxr-xr-x   2 forge forge  4096 Feb  2  2021 aproba/
drwxr-xr-x   3 root  root   4096 Jun 19  2018 archy/
...

These are packages set up in 2018 and so much older than most others updated beginning or later on this year.

Anyone any ideas how some were setup using the root user and most forge? Two, I plan to

sudo chown  forge:forge /usr/lib/node_modules/npm/node_modules/*

to solve this issue. Any reasons against this?

0 likes
2 replies
rhand's avatar
Level 6

On another Forge server setup all the node modules are owned by root:

forge@app-prod:/usr/lib/node_modules/npm/node_modules$ ll
total 1448
drwxr-xr-x 360 root root 12288 Oct 16  2020 ./
drwxr-xr-x   9 root root  4096 Oct 16  2020 ../
drwxr-xr-x   3 root root  4096 Oct 16  2020 JSONStream/
drwxr-xr-x   2 root root  4096 Oct 16  2020 abbrev/
drwxr-xr-x   2 root root  4096 Oct 16  2020 agent-base/
drwxr-xr-x   3 root root  4096 Oct 16  2020 agentkeepalive/
drwxr-xr-x   5 root root  4096 Oct 16  2020 ajv/
drwxr-xr-x   2 root root  4096 Oct 16  2020 ansi-align/
...
drwxr-xr-x   2 root root  4096 Oct 16  2020 write-file-atomic/
drwxr-xr-x   2 root root  4096 Oct 16  2020 xdg-basedir/
drwxr-xr-x   2 root root  4096 Oct 16  2020 xtend/
drwxr-xr-x   2 root root  4096 Oct 16  2020 y18n/
drwxr-xr-x   2 root root  4096 Oct 16  2020 yallist/
drwxr-xr-x   5 root root  4096 Oct 16  2020 yargs/
drwxr-xr-x   4 root root  4096 Oct 16  2020 yargs-parser/

so not sure yet if the staging server needs them all to be under root or forge.

rhand's avatar
rhand
OP
Best Answer
Level 6

chown root:root /usr/lib/node_modules/npm/node_modules/* done in the end as Mohammed at forge told me npm should be run as root for global packages. Afterwards I did

root@app-staging:/home/forge# npm update -g npm
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
/usr/bin/npx -> /usr/lib/node_modules/npm/bin/npx-cli.js
+ [email protected]
added 2 packages from 2 contributors and updated 6 packages in 6.311s

May need to upgrade still but it works now as root as it should for global packages including npm.

Please or to participate in this conversation.