Fix NPM no write permissions to global system directory
When you install npm packages globally using the -g flag, you might encounter an error message indicating that you do not have write permissions to the global system directory. This issue typically arises due to insufficient permissions for the user account trying to perform the installation.
EACCES errors indicate permission denied issues.
kc@kcserver:~$ npm install -g pnpm
npm error code EACCES
npm error syscall mkdir
npm error path /usr/lib/node_modules/lib
npm error errno -13
npm error Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/lib'
npm error at async mkdir (node:internal/fs/promises:861:10)
npm error at async Arborist.reify (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:109:7)
npm error at async Install.exec (/usr/lib/node_modules/npm/lib/commands/install.js:150:5)
npm error at async Npm.exec (/usr/lib/node_modules/npm/lib/npm.js:208:9)
npm error at async module.exports (/usr/lib/node_modules/npm/lib/cli/entry.js:67:5) {
npm error errno: -13,
npm error code: 'EACCES',
npm error syscall: 'mkdir',
npm error path: '/usr/lib/node_modules/lib'
npm error }
npm error
npm error The operation was rejected by your operating system.
npm error It is likely you do not have the permissions to access this file as the current user
npm error
npm error If you believe this might be a permissions issue, please double-check the
npm error permissions of the file and its containing directories, or try running
npm error the command again as root/Administrator.
npm error A complete log of this run can be found in: /home/kc/.npm/_logs/2025-12-23T09_36_53_527Z-debug-0.logTo resolve this issue, you have a few options.
Method 1: Change NPM’s default global directory (Recommended)
You can configure npm to use a different directory for global installation where you have write permissions.
-
Create a folder for global installations
mkdir ~/.npm-global -
Configure NPM to use this new path
npm config set prefix '~/.npm-global' -
Update shell environment
~/.bashrc# add the following line at the end of the file export PATH=~/.npm-global/bin:$PATH -
Apply the changes
source ~/.bashrc -
Re-run the installation
npm install -g <package>
Method 2: Use a Node Version Manager
There are some tools like nvm (Node Version Manager)Â can install Node.js and NPM directly in your user home directory that actually auto bypass the /usr/lib permission issues.
-
Download and install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash -
Export NVM dir
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion -
Install a version of Node
nvm install node -
Install package
npm install -g <package>
Method 3: Change default global directory ownership
You can change the ownership of the existing node_modules folder to your current user.
sudo chown -R $(whoami) /usr/lib/node_modules