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
What's the command to install Node on Ubuntu?
Can't install NodeJS v18.12.0 / v18.12.1 on Ubuntu 20.04?
Why is it so hard to update Node on Linux? And why I still see old version of node after using "n" to update
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
Hk, Ubuntu 22 LTS when running apt-get install nodejs i get version 12 which Mesh installer fails on loads of dependencies needing to be v14 or newer. Cant find how to get a new version of Node on Ubuntu, the manual lists a command that i get output errors with.
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 RestartedPer the Node.js website:
# Using Debian/Ubuntu
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
Then, you will have the latest version of Node.js.
If you're not a fan of curl <url> | bash -, or are using an unsupported distribution, you can try a manual installation.
Node is one of the easier projects to build. Just change the version as that continues to change.
Browse to http://nodejs.org/dist/latest/ to find out the latest package version.
cd /usr/local/src
wget http://nodejs.org/dist/latest/node-v7.2.1.tar.gz
tar -xvzf node-v7.2.1.tar.gz
cd node-v7.2.1
./configure
make
sudo make install
which node
You should see /usr/local/bin/node.
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
Install NVM, and the install node using nvm. Here is an example.
Install nvm
ubuntu@ip-172-26-0-227:~$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 16555 100 16555 0 0 198k 0 --:--:-- --:--:-- --:--:-- 199k => Compressing and cleaning up git repository => Appending nvm source string to /home/ubuntu/.bashrc => Appending bash_completion source string to /home/ubuntu/.bashrc => Close and reopen your terminal to start using nvm or run the following to use it now: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completionSource bashrc so nvm can be loaded, or close and re open terminal.
ubuntu@ip-172-26-0-227:~$ source /home/ubuntu/.bashrc
Now, install node version, passing the version..etc.
ubuntu@ip-172-26-0-227:~$ nvm install v12.22.10 Downloading and installing node v12.22.10... Downloading https://nodejs.org/dist/v12.22.10/node-v12.22.10-linux- x64.tar.xz..100.0% Computing checksum with sha256sum Checksums matched! Now using node v12.22.10 (npm v6.14.16) Creating default alias: default -> v12.22.10