Loading...
Loading...
npm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /usr/local/lib/node_modulesnpm doesn't have permission to write to the global node_modules directory. This commonly happens when npm was installed as root and you're trying to install packages as a regular user.
Install Node.js via nvm — it installs to your home directory, avoiding permission issues entirely.
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Restart terminal, then install Node
nvm install --lts
nvm use --lts
# Now npm install works without sudo
npm install -g package-nameConfigure npm to use a directory in your home folder.
# Create a directory for global packages
mkdir ~/.npm-global
# Configure npm to use it
npm config set prefix '~/.npm-global'
# Add to your ~/.bashrc or ~/.zshrc
export PATH=~/.npm-global/bin:$PATH
# Reload shell config
source ~/.bashrc