First remove nodejs using,
sudo apt-get purge --auto-remove nodejs
Then after, if curl is not installed then run the below command
sudo apt-get install curl
Then after run the below 2 commands,
Answer from Avinash Antala on Stack Overflowcurl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
Videos
First remove nodejs using,
sudo apt-get purge --auto-remove nodejs
Then after, if curl is not installed then run the below command
sudo apt-get install curl
Then after run the below 2 commands,
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
You can install the latest version from non Official Ubuntu repos.
First you can use a PPA (personal package archive) maintained by NodeSource.
curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
Change the permission to 755 or 764 and run the file
sudo bash nodesource_setup.sh
The PPA will be added to your configuration and now you can install the Node.js package...
sudo apt install nodejs
node -v
v16.10.0
the complete instructions for installing node from that distribution is two commands:
# install the source list, let apt-get install 'find' the nodejs package
curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash -
# apt-get now knows about nodejs package
sudo apt-get install -y nodejs
you'll find that when you follow these instructions, the script will print how to install yarn, and you should do that, also several commands (for adding sources, keys, and then installing the packages from those lists).
Suggested method
I would suggest using the n library, because it doesn't require any OS modification, like so:
sudo npm i -g n
sudo n 20
use the following link to download https://nodejs.org/dist/v12.13.0/node-v12.13.0-x64.msi
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -sudo apt install nodejsCheck:
$ node --versionOutput: v10.16.3Check:
$ npm --versionOutput: 6.9.0
Try using n. After installing node in any way, eg. as described below:
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
you should have npm available. Install n with:
npm install -g n
and select correct version
n lsrto list available versionsn latestto use latestn 12.0.0to use 12.0
Homebridge is telling me to update NodeJS to the latest version (v18.12.1). However, my Ubuntu 20.04 system refuses to see a newer version than v18.11.0 (see log output). Any idea how to solve this, preferably without upgrading Ubuntu to a newer version?
kraken@scylla:~$ sudo hb-service update-node
ℹ Updating Node.js from v18.11.0 to v18.12.1...
ℹ Updating from NodeSource...
Hit:1 http://old-releases.ubuntu.com/ubuntu impish InRelease
Hit:2 http://old-releases.ubuntu.com/ubuntu impish-security InRelease
Get:3 https://download.docker.com/linux/ubuntu hirsute InRelease [48,9 kB]
Hit:4 https://deb.nodesource.com/node_18.x impish InRelease
Fetched 48,9 kB in 1s (56,9 kB/s)
Reading package lists... Done
## Installing the NodeSource Node.js 18.x repo...
## Populating apt-get cache...
+ apt-get update
Hit:1 https://deb.nodesource.com/node_18.x impish InRelease
Get:2 https://download.docker.com/linux/ubuntu hirsute InRelease [48,9 kB]
Hit:3 http://old-releases.ubuntu.com/ubuntu impish InRelease
Hit:4 http://old-releases.ubuntu.com/ubuntu impish-security InRelease
Fetched 48,9 kB in 1s (88,5 kB/s)
Reading package lists... Done
## Confirming "impish" is supported...
+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_18.x/dists/impish/Release'
## Adding the NodeSource signing key to your keyring...
+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg >/dev/null
## Creating apt sources list file for the NodeSource Node.js 18.x repo...
+ echo 'deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x impish main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x impish main' >> /etc/apt/sources.list.d/nodesource.list
## Running `apt-get update` for you...
+ apt-get update
Hit:1 http://old-releases.ubuntu.com/ubuntu impish InRelease
Get:2 https://download.docker.com/linux/ubuntu hirsute InRelease [48,9 kB]
Hit:3 http://old-releases.ubuntu.com/ubuntu impish-security InRelease
Hit:4 https://deb.nodesource.com/node_18.x impish InRelease
Fetched 48,9 kB in 0s (105 kB/s)
Reading package lists... Done
## Run `sudo apt-get install -y nodejs` to install Node.js 18.x and npm
## You may also need development tools to build native addons:
sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
nodejs is already the newest version (18.11.0-deb-1nodesource1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
ℹ Restarting Homebridge Service...
✔ Homebridge Restarted