To update nodejs to 14.x run the following commands:
sudo apt update
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt install -y nodejs
node -v
After running the final command you should see:
v14.15.0
Answer from Ahmed Boutaraa on askubuntu.comTo update nodejs to 14.x run the following commands:
sudo apt update
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt install -y nodejs
node -v
After running the final command you should see:
v14.15.0
Update for 2024
Since this question was posted, version 20 became the newest LTS version. So Ahmed Boutaraa's answer was correct for the version 14 part of the question, but people stumbling on this question may be seeking the most recent LTS. If you follow those instructions, you will be stuck in version 14.
Luckily, NodeSource also provides an installation script that installs the current LTS rather than a specific version. That should make this answer a bit more future-proof. You can also get the same info straight from the source.
As an aside, there is a script called nvm that is great for managing your node version. It makes it easy to install multiple versions, like if you work with multiple projects with different version requirements or if you want to experiment with the latest version and easily switch back to LTS for regular work. You can find installation instructions on their repository.
How to install the latest LTS version
This set of instructions will install whatever version is the latest LTS version. When a new version is released, you may have to run these instructions again to pull the new install script for the new version.
# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
# OR as root
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
How to install the latest non-LTS version
This set of instructions will install whatever version is the latest non-LTS version. When a new version is released, you may have to run these instructions again to pull the new install script for the new version.
# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs
# OR as root
curl -fsSL https://deb.nodesource.com/setup_current.x | bash -
apt-get install -y nodejs
How to lock into v21 (latest, for now)
# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash -
sudo apt-get install -y nodejs
# OR as root
curl -fsSL https://deb.nodesource.com/setup_21.x | bash -
apt-get install -y nodejs
How to lock into v20 (current LST)
# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# OR as root
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
How do I update the node version to 20.9.0
How to update node on my WSL Ubuntu?
npm - How can I install Node.js version 18 on Ubuntu 22.04? - Stack Overflow
Can't install NodeJS v18.12.0 / v18.12.1 on Ubuntu 20.04?
Videos
Ubuntu Linux/Mac
The module n makes version-management easy:
sudo npm install n -g
For the latest stable version:
n stable
For the latest version:
n latest
Debian 10
Upgrade older versions of node and npm on Debian 10 as follows:
sudo su -c 'curl -sL https://deb.nodesource.com/setup_18.x | bash -'
sudo apt-get install nodejs -y
sudo apt update
sudo apt upgrade
sudo npm install -g [email protected]
node --version
npm --version
Note: Replace setup_18 with the latest long-term support release.
Windows
Just reinstall node from the .msi in Windows from the node website.
All Platforms (Mac, Linux & Windows) 2024
If you just need to upgrade your old version of Node.js to the latest one and don't need multiple versions, simply over-write your existing executable with the new one.
Download the Latest Node.js from nodejs.org/en/download
This Just Works! TM on all platforms and is the easiest/fastest method.
When you run node -v in your terminal you will see the the latest version.
Mac
If you originally installed Node.js using brew then run:
brew upgrade node
Managing Multiple Versions of Node.js:
If you need to run multiple versions of Node.js on your machine e.g. if you have an older project that targets a specific version on AWS Lambda, then NVM (Node Version Manger) is your friend!
Step 1 - Get NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
If you're curious about the installation command read the source code
... its been reviewed by several node.js security experts
Step 2 - Install the Specific Version of Node.js you need
Once you've got NVM you can install a specific version of Node.js using the nvm command:
nvm install v22.16.0
Note: you may need to close & re-open your terminal window for nvm command to be available.
You should expect to see something like this in your terminal:
Now using node v22.16.0
You now have the latest Node.js on your machine.
And if you need to temporarily switch to a different/previous version, you can do it with a simple nvm command.
Note: avoid using
sudowith Node/NPM as it violates the security principal of least privilege
NVM is considered "better" than N for managing multiple Node.js versions because the verbose commands mean it is much easier to keep track of what you are doing in your Terminal/SSH Log. It is used by the team at NPM the creators/custodians of the Node.js World!
I have downloaded node on my win and it shows 20.11.1 while using node -v command. but when I use the same command on wsl ubuntu it shows v10.19.0. how to update it on wsl?
installed node using sudo apt install node
I recommend using Node Version Manager:
NB: Node Version Manager (nvm) allows you to install multiple node versions and choose between them depending on which software you want to support; that is, manage multiple node versions.
Installing Node Version Manager
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Once you have Node Version Manager installed
- Confirm the available remote versions by running
nvm ls-remote - Run in your terminal
nvm install <version>for example,nvm install 18to install version 18 of Node - List installed versions with
nvm list - Run
nvm use 18to start using version 18 of Node - Note: you can be more explicit, for example:
nvm install 14.17.0
Install nodejs v20 on Debian and Ubuntu based distributions
step 1 : Download and import the Nodesource GPG key
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
step 2 : Create deb repository
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
optional: here we are installing nodejs v20 but if you want to install v18 change NODE_MAJOR=18 in above command. Similarly if you want to install nodejs v16 then change NODE_MAJOR=16.
step 3 : Run Update and Install
sudo apt-get update
sudo apt-get install nodejs -y
congratulations you just installed nodejs
To uninstall nodejs
sudo apt-get purge nodejs &&\
rm -r /etc/apt/sources.list.d/nodesource.list &&\
rm -r /etc/apt/keyrings/nodesource.gpg