How to install node js latest version on any linux distro

Being new to Linux distro like Linux mint or ubuntu or any other distro 

and you are node developer you use node js and are stuck because the repo has old node and npm versions

or working on MERN stack projects and run into errors like this


then its due to old node and npm version which is not available in official repos on major Linux distros

so I'm here to guide you to install latest version on any Linux distro step by step:

  • Go to official website of node js on you browser https://nodejs.org/en/
  • Download the LTS versions it might be different version for you based on when you visit there website
  • After the download open terminal on downloads folder and run the following commands
  • Make sure you have xzutils all major distro have it preinstalled sudo apt install xz-utils
  • Extract the file by typing sudo tar -xvf name_of_file 
        e.g: sudo tar -xvf node-v16.13.2-linux-x64.tar.xz (in my case)
  • Then type : sudo cp -r directory_name/{bin,include,lib,share} /usr/
e.g: sudo cp -r node-v16.13.2-linux-x64/{bin,include,lib,share} /usr/ (remember this is the extracted directory not the tar.xz file)

  •  Check node version by typing  node --version
  • Also npm version by typing npm --version
  • Done! it will give now u have the recent version of node and npm installed on your system you can delete the tar.xz file from downloads but note: never delete the extracted directory

 

Comments