25

I'm pretty new to Ubuntu. I could install Node.js to the latest version 14.7.0 but the program I'm using (Jhipster) tells me that I need to install the Long Term Support (LTS, currently 12.18.3) and do not have any idea about how to do it.

There is the node-v12.18.3-linux-x64.tar.xz file that looks like a zip file in Windows, but I do not know how to install it (it does not install itself when the file manager opens it)

I tried to google on how to choose the version, but I could find how to do it. Please, explain it for dummies. Thanks.

Mike
  • 363

6 Answers6

60

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
  • 1
    +1 for straightforward solution – artu-hnrq Aug 09 '21 at 01:21
  • 1
    I found this very useful, and used the LTS install script, which I assume may update as new LTS versions are released. https://github.com/nodesource/distributions/blob/master/README.md "curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -" – Mazrick Sep 23 '21 at 12:25
  • Thanks after I run the commands by Ahemd, I also needed to run sudo apt-get install -y nodejs – Majali Apr 17 '22 at 07:19
11

Update for 2022

Since this question was posted, version 16 became the newest LTS version. So Ahmed Boutaraa's answer is 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.

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

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

As root

curl -fsSL https://deb.nodesource.com/setup_current.x | bash - apt-get install -y nodejs

How to lock into v17 (latest, for now)

# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -
sudo apt-get install -y nodejs

As root

curl -fsSL https://deb.nodesource.com/setup_17.x | bash - apt-get install -y nodejs

How to lock into v16 (current LST)

# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

As root

curl -fsSL https://deb.nodesource.com/setup_16.x | bash - apt-get install -y nodejs

Jon Musselwhite
  • 230
  • 2
  • 5
9
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source ~/.bashrc
nvm list-remote
nvm install v14.17.6

In last command choose the version you want to install from list shown in previous command.

4

I followed the instructions from Ahmed Boutaraa's answer, which work fine, but I just did some changes to get the current LTS version.

I just changed the version of node in step 2 from:

curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -

to:

curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -

Now I run:

node -v

And the version is:

v16.14.2
Malik
  • 41
2

From the official 'NodeSource Node.js Binary Distributions' github repo:

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

NODE_MAJOR=20 # can be 16, 18, 20, 21 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

sudo apt-get update sudo apt-get install nodejs -y

jstm
  • 141
1

I found this very easy way of upgrading node-

  1. First, clear the npm cache:

npm cache clean -f

  1. Install n, Node’s version manager:

    sudo npm install -g n

3.With the n module installed, you can use it to:

  • Install the latest stable version:

    sudo n stable

*Install the latest release:

sudo n latest
  • Install a specific version:

    sudo n [version.number]

Shiv
  • 11