Installing and Managing Development ToolsLesson 4.1
How to install Node.js in WSL2 using nvm
why not apt for Node.js, nvm installation, nvm install, nvm use, nvm alias default, multiple Node versions, .nvmrc file, npm global packages
Installing Node.js with nvm
Installing Node.js via apt gives you an outdated version with broken global package permissions. The correct approach is nvm (Node Version Manager), which installs Node in your home directory without needing sudo.
Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrcInstall and use a Node version
nvm install 20
nvm install --lts
nvm use 20
nvm alias default 20
node --version
npm --versionSwitching versions per project
nvm install 18
nvm use 18
# Or use .nvmrc in the project root:
echo "20" > .nvmrc
nvm useInstalling global npm packages
npm install -g pnpm
npm install -g nodemon
npm install -g typescriptBecause nvm installs Node inside ~/.nvm, global packages install there too — no sudo required, no permission errors.
