I am trying to update node on UBUNTU (version 22.04.4 LTS) and have followed the official procedure on their site:
# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# download and install Node.js (you may need to restart the terminal)
nvm install 21
# verifies the right Node.js version is in the environment
node -v # should print `v21.7.3`
# verifies the right NPM version is in the environment
npm -v # should print `10.5.0`
At first everything seemed OK, giving me the exact versions of both node and npm. But after closing and reopening the terminal it gives me the version of node: v23.0.0-nightly2024071586415e4688
and as npm version says:
npm warn cli npm v10.8.2 does not support Node.js v23.0.0-nightly2024071586415e4688. This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.
10.8.2
How can such a thing happen if I have copied and pasted exactly the commands the official website says to use???
How can I solve it? I’ve tried deleting and repeating the same procedure but I get the same result as above, I’ve tried restarting the pc and repeating with a newer version but nothing, and I’ve tried the same with an older version…I always get the same problem!
2
Answers
I finally solved it with
nvm alias default 21.7.3
and then withnvm use 21.7.3
.It seems to work
Step 1: Install nvm
Step 2: Load nvm into the current shell session
Step 3: Install Node.js version 21
Step 4: Verify the installation