How to fix npm errors without writing sudo in macOS?

16 views Asked by At

I have to write sudo before running any npm command in my VS code terminal in MacBook Air (OS: macOS Sonoma 14.4). Example: sudo npm install sudo npc create-react-app my app If I didn't "sudo" the command will not execute, while others users are doing without writing sudo.

FYI: I have node.js v20.10.0 and npm version 10.2.4 installed globally in my system.

1

There are 1 answers

0
det.antoine On

You can add it to your PATH. First evaluate the node path:

sudo which node

In ~/.bashrc or ~/.zshrc, add the line with the evaluated node_path:

export PATH="node_path:$PATH"

In the end, you need to restart a shell or source the file.