0

I have tried various methods by which I can install the latest version of nodejs on my operating system but was unsuccessful.

In the end it always ends up installing version v.4.2.6

When I run the commands below, it always shows an error as shared in the screenshots of my terminal.
Current release:
sudo apt-get install curl python-software-properties curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -

or LTS release:
sudo apt-get install curl python-software-properties curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

// throws error Version:
enter image description here


Trying to execute node 11 script:
enter image description here


o/p of the above script:
enter image description here

Please guide me how can it be fixed. I have followed some of the other stackoverflow links but couldn't make it.

Thanks you for your help.

Roysh
  • 1,542
  • 3
  • 16
  • 26
Amir Mustafa
  • 85
  • 2
  • 7

2 Answers2

3

I recommand uninstalling your current NodeJS version and install nvm instead. Then you can manage all node version with nvm.

Method 1: I followed this link and it was successful: updating nodejs on ubuntu 16.04

Method 2:

You can either skip above link and follow the below steps:

Using Node Version Manager (NVM):

Install it by following instructions here

Test your installation:

close your current terminal, open a new terminal, and run:

command -v nvm

Use it to install as many versions as u like:

nvm install 8              # Install nodejs 8
nvm install --lts          # Install latest LTS (Long Term Support) version

List installed versions:

nvm ls

Use a specific version:

nvm use 8                  # Use this version on this shell

Set defaults:

nvm alias default 8        # Default to nodejs 8 on this shell
nvm alias default node     # always use latest available as default nodejs for all shells
Leo
  • 741
  • 6
  • 14
1

If you have npm installed -

run

sudo npm cache clean -f
sudo npm install -g n

install n globally

npm i -g n 

then switch to the latest stable node version using n

n stable
Roysh
  • 1,542
  • 3
  • 16
  • 26