Update Global npm Packages on macOS Faster
Update all global npm packages on macOS, fix permissions, and add a reusable shell function.
Update Global npm Packages on macOS Faster
Check outdated global packages
1
npm outdated -g
Update to wanted versions (semver-safe)
1
npm update -g
Update to absolute latest versions
1
2
3
npx npm-check-updates -g
npx npm-check-updates -g -u
npm install -g
Fix EACCES permission issues on macOS
1
2
3
4
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Add a reusable shell function
If the above flow is inconvenient, add a helper to your shell and reload:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cat <<'EOF' >> ~/.zshrc
npm_update_globals() {
echo "Outdated (global):"
npm outdated -g || true
echo "Updating to wanted versions…"
npm update -g
if command -v npx >/dev/null 2>&1; then
echo "Upgrading to absolute latest (ignores semver)…"
npx npm-check-updates -g && npx npm-check-updates -g -u && npm install -g
fi
echo "Verify:"
npm outdated -g || true
}
EOF
source ~/.zshrc
Use the helper:
1
npm_update_globals
Keeping global npm packages current reduces breakage, surfaces security fixes sooner, and simplifies local tooling parity across machines. Configure a user-owned prefix once, then rely on the function to standardize updates in a single command.
☕ Support My Work
If you found this post helpful and want to support more content like this, you can buy me a coffee!
Your support helps me continue creating useful articles and tips for fellow developers. Thank you! 🙏
This post is licensed under CC BY 4.0 by the author.