Installing the latest version of node using nvm:
Install the latest nvm through its Github repo:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
source ~/.bashrc
check the latest version of node and select it:
nvm list-remote
Out:
...
v20.15.0 (LTS: Iron)
v20.15.1 (LTS: Iron)
v20.16.0 (Latest LTS: Iron)
v21.0.0
v21.1.0
v21.2.0
v21.3.0
v21.4.0
v21.5.0
v21.6.0
v21.6.1
v21.6.2
v21.7.0
v21.7.1
v21.7.2
v21.7.3
v22.0.0
v22.1.0
v22.2.0
v22.3.0
v22.4.0
v22.4.1
v22.5.0
v22.5.1
v22.6.0
Install the desired version of node:
nvm install v20.16.0
Answer from Benyamin Jafari on askubuntu.comWhat's the command to install Node on Ubuntu?
Install Node.js on Ubuntu - Stack Overflow
node.js - Install a specific nodejs version with apt-get - Stack Overflow
node.js - How to install a specific version of Node on Ubuntu/Debian? - Stack Overflow
Videos
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.
Installing the latest version of node using nvm:
Install the latest nvm through its Github repo:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
source ~/.bashrc
check the latest version of node and select it:
nvm list-remote
Out:
...
v20.15.0 (LTS: Iron)
v20.15.1 (LTS: Iron)
v20.16.0 (Latest LTS: Iron)
v21.0.0
v21.1.0
v21.2.0
v21.3.0
v21.4.0
v21.5.0
v21.6.0
v21.6.1
v21.6.2
v21.7.0
v21.7.1
v21.7.2
v21.7.3
v22.0.0
v22.1.0
v22.2.0
v22.3.0
v22.4.0
v22.4.1
v22.5.0
v22.5.1
v22.6.0
Install the desired version of node:
nvm install v20.16.0
INSTALL (Node Version Manager) be following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashNow, reopen your terminal, or "
exit" command if you server ssh and reconnectGet packages by following command:
nvm install 20Veryfiy node by:
node -v# should print v20.16.0Finally check the npm:
npm -v # should print '10.8.1'
Gongrates! You have done!
Simply follow the instructions given here:
Example install:
sudo apt-get install python-software-properties python g++ make sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejsIt installs current stable Node on the current stable Ubuntu. Quantal (12.10) users may need to install the software-properties-common package for the
add-apt-repositorycommand to work:sudo apt-get install software-properties-commonAs of Node.js v0.10.0, the nodejs package from Chris Lea's repo includes both npm and nodejs-dev.
Don't give sudo apt-get install nodejs npm. Just sudo apt-get install nodejs.
As of today, you can simply install it with:
sudo apt-get install nodejs
Make sure you have the following packages:-
sudo apt-get install \
apt-transport-https \
curl \
software-properties-common
Enable the NodeSource repository by using a command:-
sudo curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
After enabling the repository, install Node.js using a command:-
sudo apt-get install nodejs
If you're doing this for a Docker image, why not just use the Node Docker image with the version you need?
The n module worked for me.
Run this code to clear npm’s cache, install n, and install the latest stable version of Node:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
See: http://www.hostingadvice.com/how-to/update-node-js-latest-version/
And: https://www.npmjs.com/package/n
To install a specific version of node:
sudo n 18.17.1
To check what version:
node -v
You might need to restart
NVM (Node Version manager)
https://github.com/nvm-sh/nvm
Advantages:
allows you to use multiple versions of Node and without sudo
is analogous to Ruby RVM and Python Virtualenv, widely considered best practice in Ruby and Python communities
downloads a pre-compiled binary where possible, and if not it downloads the source and compiles one for you
Tested in Ubuntu 17.10:
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.nvm/nvm.sh
nvm install 0.9.0
nvm install 0.9.9
nvm use 0.9.0
node --version
#v0.9.0
nvm use 0.9.9
node --version
#v0.9.9
For the particular case of the most recent long term support version (recommended if you can choose):
nvm install --lts
nvm use --lts
npm --version
npm install --global vaca
vaca
Since the sourcing has to be done for every new shell, the install script hacks adds some auto sourcing to the end of your .barshrc. That works, but I prefer to remove the auto-added one and add my own:
f="$HOME/.nvm/nvm.sh"
if [ -r "$f" ]; then
. "$f" &>'/dev/null'
nvm use --lts &>'/dev/null'
fi
With this setup, you get for example:
which node
gives:
/home/ciro/.nvm/versions/node/v0.9.0/bin/node
and:
which vaca
gives:
/home/ciro/.nvm/versions/node/v0.9.0/bin/vaca
and if we want to use the globally installed module:
npm link vaca
node -e 'console.log(require.resolve("vaca"))'
gives:
/home/ciro/.nvm/versions/node/v0.9.0/lib/node_modules/vaca/index.js
as mentioned at:
- NodeJS require a global module/package
- How do I import global modules in Node? I get "Error: Cannot find module <module>"?
so we see that everything is completely contained inside the specific node version.
For projects however, you are better off just using packages installed locally under node_modules and npx for executable to be able to have independent versions across projects, global usage is mostly for the Node executable itself and global CLI utilities not specific to any project.
Setting the NPM version
Simply:
npm install [email protected] -g
The executable is placed inside the current NVM version, so everything remains nice and isolated, e.g.:
which npm
gives something like:
/home/ciro/.nvm/versions/node/v14.17.0/bin/npm
How can I change the version of npm using nvm?
I recommend using Node Version Manager:
NB: Node Version Manager (nvm) allows you to install multiple node versions and choose between them depending on which software you want to support; that is, manage multiple node versions.
Installing Node Version Manager
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Once you have Node Version Manager installed
- Confirm the available remote versions by running
nvm ls-remote - Run in your terminal
nvm install <version>for example,nvm install 18to install version 18 of Node - List installed versions with
nvm list - Run
nvm use 18to start using version 18 of Node - Note: you can be more explicit, for example:
nvm install 14.17.0
Install nodejs v20 on Debian and Ubuntu based distributions
step 1 : Download and import the Nodesource GPG key
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
step 2 : Create deb repository
NODE_MAJOR=20
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
optional: here we are installing nodejs v20 but if you want to install v18 change NODE_MAJOR=18 in above command. Similarly if you want to install nodejs v16 then change NODE_MAJOR=16.
step 3 : Run Update and Install
sudo apt-get update
sudo apt-get install nodejs -y
congratulations you just installed nodejs
To uninstall nodejs
sudo apt-get purge nodejs &&\
rm -r /etc/apt/sources.list.d/nodesource.list &&\
rm -r /etc/apt/keyrings/nodesource.gpg