The safest and cleanest way I’ve found is to use Node Version Manager (nvm).
It lets you install and switch between Node versions easily.
First, install nvm if you haven’t:
bash
Copy
Edit
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Then run:
bash
Copy
Edit
nvm install node # installs latest stable
nvm use node # switches to it
nvm alias default node
This keeps things isolated and avoids permission issues or messing with system binaries.
You can still update npm after that with:
bash
Copy
Edit
npm install -g npm