0

I'm getting crazy installing Node 16.x on Ubuntu.

I use

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

And then

sudo apt-get install -y nodejs

But the version installed is the 18.x

sudo apt list nodejs -a

Return me

nodejs/kinetic 18.7.0+dfsg-5ubuntu1 amd64
nodejs/unknown 16.18.1-deb-1nodesource1 amd64

How can I remove the first one?

Roberto Pezzali
  • 141
  • 1
  • 1
  • 9

1 Answers1

2

I had problems with this as well. So there are many tutorials how to install different version of nodejs but they did not work in my case. However the last with nvm did.

Method 1: Install nodejs from specific source

cd ~
curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh

by changing setup_16.x to your version, you change the version

sudo bash nodesource_setup.sh

then you test sources with

# sample on Ubuntu 22.10
$ cat /etc/apt/sources.list.d/nodesource.list
deb https://deb.nodesource.com/node_16.x focal main
deb-src https://deb.nodesource.com/node_16.x focal main

Then you install nodejs from that source (did not work in my case)

sudo apt -y install nodejs

And check installed version

node -v

This should return

v16.19.0

but in my case (Ubuntu 22.10) I got the new version

v18.7.0

Method 2: Install Node Vesrion Manager or nvm This worked in my case:

sudo apt install curl 
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash 
source ~/.bashrc 

Now to install an older version of nodejs with nvm

you can first check available versions by

nvm list-remote

and then install specific version by (ex. version v16.19.0)

nvm install 16.19.0

and check with:

$ node -v
v16.19.0

To install latest version of node with nvm

nvm install node 

$ node -v
v18.7.0

Hope this helps someone to

Greg G
  • 36
  • 2