Node.js & npm Troubleshooting
This guide helps you resolve common Node.js and npm issues that may occur during Forge installation.
Permission Errors with npm
If you encounter permission errors when installing Forge globally, here are the recommended solutions:
Solution 1: Use a Node.js Version Manager (Recommended)
Using a Node.js version manager like nvm is the safest and most reliable approach:
For macOS and Linux:
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Restart your terminal or reload your profile
source ~/.bashrc # or ~/.zshrc for zsh users
# Install and use the latest Node.js
nvm install node
nvm use node
# Now install Forge
npm i -g forgecode@latest
For Windows:
# Install nvm-windows from: https://github.com/coreybutler/nvm-windows
# Then in a new command prompt:
nvm install latest
nvm use latest
npm i -g forgecode@latest
Solution 2: Configure npm to Use a Different Directory
If you prefer not to use a version manager, configure npm to install global packages in your home directory:
# Create a directory for global packages
mkdir ~/.npm-global
# Configure npm to use the new directory
npm config set prefix '~/.npm-global'
# Add the new directory to your PATH
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
# For zsh users, use ~/.zshrc instead of ~/.bashrc
# Reload your profile
source ~/.bashrc # or source ~/.zshrc
# Now install Forge
npm i -g forgecode@latest