Node.js – How to manage Node.js versions on Linux

Node.js

Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications.

Watch the video on how to add, change, or remove Node.js versions.

Instructions on how to manage Node.js versions

Install Node.js

node -version

Output

Command 'node' not found, but can be installed with:
apt install nodejs
Please ask your administrator.

Install

sudo apt install nodejs

Check the installation

node -v

Output

v12.22.9

Install npm

npm -v

Output

Command 'npm' not found, but can be installed with:
apt install npm
Please ask your administrator.

Installation

sudo apt install npm

Check the installation

npm -v

Output

8.5.1

Install Node.js manager

sudo npm install -g n

Check the installation

sudo n

Install stable Node.js version

sudo n stable

Output

  installing : node-v20.8.0
       mkdir : /usr/local/n/versions/node/20.8.0
       fetch : https://nodejs.org/dist/v20.8.0/node-v20.8.0-linux-x64.tar.xz
     copying : node/20.8.0
   installed : v20.8.0 (with npm 10.1.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)

Install the latest Node.js version

sudo n latest

Output

     copying : node/20.8.0
   installed : v20.8.0 (with npm 10.1.0)

Install custom version

sudo n 16

Output

  installing : node-v16.20.2
       mkdir : /usr/local/n/versions/node/16.20.2
       fetch : https://nodejs.org/dist/v16.20.2/node-v16.20.2-linux-x64.tar.xz
     copying : node/16.20.2
   installed : v16.20.2 (with npm 8.19.4)

Change Node.js version

sudo n

Output

  ο node/16.20.2
    node/20.8.0

Use up/down arrow keys to select a version, return key to install, d to delete, q to quit
https://www.mldgroup.com

Vyštudovaný top manažér pôsobiaci najmä ako manažér, marketér, softvérový inžinier, konzultant, bloger, YouTuber a zatiaľ neúspešný hudobník a producent. V rámci praxe pôsobil v rôznych odvetviach na rôznych pozíciách v malých aj veľkých firmách, vrátane spoluprác a partnerstiev s významnými firmami či poradenskými spoločnosťami.

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená. Vyžadované polia sú označené *