Ubuntu 24.04
Sponsored Link

Node.js : Install version management tool2024/05/31

 

Install Node.js version management tool [n] command.

[1]

Install Node.js, refer to here.

[2] Install [n] command and upgrade Node.js.
root@dlp:~#
npm install -g n

added 1 package in 719ms

# show the [stable] version

root@dlp:~#
n --stable

20.14.0
# show the [latest] version

root@dlp:~#
n --latest

22.2.0
# install the [stable] version

root@dlp:~#
n stable

  installing : node-v20.14.0
       mkdir : /usr/local/n/versions/node/20.14.0
       fetch : https://nodejs.org/dist/v20.14.0/node-v20.14.0-linux-x64.tar.xz
     copying : node/20.14.0
   installed : v20.14.0 (with npm 10.7.0)

Note: the node command changed location and the old location may be remembered in your current shell.
         old : /usr/bin/node
         new : /usr/local/bin/node
If "node --version" shows the old version then start a new shell, or reset the location hash with:
hash -r  (for bash, zsh, ash, dash, and ksh)
rehash   (for csh and tcsh)

root@dlp:~#
/usr/local/bin/node -v

v20.14.0
# install the [latest] version

root@dlp:~#
n latest

  installing : node-v22.2.0
       mkdir : /usr/local/n/versions/node/22.2.0
       fetch : https://nodejs.org/dist/v22.2.0/node-v22.2.0-linux-x64.tar.xz
     copying : node/22.2.0
   installed : v22.2.0 (with npm 10.7.0)

root@dlp:~#
/usr/local/bin/node -v

v22.2.0
# show installed versions

root@dlp:~#
n ls

node/20.14.0
node/22.2.0

# switch to another version

root@dlp:~#
n node/20.14.0

     copying : node/20.14.0
   installed : v20.14.0 (with npm 10.7.0)

root@dlp:~#
/usr/local/bin/node -v

v20.14.0
# deb package installed Node.js

root@dlp:~#
/usr/bin/node -v

v18.19.1
Matched Content