Steps to download and install node in ubuntu

Step 1: Download latest or recommended node .tar.xz file from https://nodejs.org/en/

or you can download node version 14.15.5 (.tar.xz file) directly from here ->

https://nodejs.org/dist/v14.15.5/node-v14.15.5-linux-x64.tar.xz

Step 2: Go to the directory in which (.tar.xz file) is downloaded.

In my case --> /Download directory

Step 3: Update System Repositories

sudo apt update

Step 4: Install the package xz-utils

sudo apt install xz-utils

Step 5: To Extract the .tar.xz file

sudo tar -xvf name_of_file

In my case --> sudo tar -xvf node-v14.15.5-linux-x64.tar.xz

Step 6: sudo cp -r directory_name/{bin,include,lib,share} /usr/

In my case --> sudo cp -r node-v14.15.5-linux-x64/{bin,include,lib,share} /usr/

Step 7: Check the node version

node --version

Result In my case -> v14.15.5

Answer from Azam Baig on Stack Overflow
Top answer
1 of 13
59

You can download this file from the browser or from the console. The latter is shown below (note: the specific Node.js version might be different for you):

Example :

wget http://nodejs.org/dist/v8.1.1/node-v8.1.1-linux-x64.tar.gz

sudo tar -C /usr/local --strip-components 1 -xzf node-v8.1.1-linux-x64.tar.gz

 #tar options:

 -x, --extract, --get
   extract files from an archive

 -f, --file ARCHIVE
   use archive file or device ARCHIVE

 -z, --gzip, --gunzip --ungzip`

You may find list of node version on http://nodejs.org/dist/

You should now have both Node.js and npm installed in “/usr/local/bin”. You can check this typing:

ls -l /usr/local/bin/node ls -l /usr/local/bin/npm

*An alternative way to install Node.js via the package manager:

Installing Node.js via package manager

2 of 13
26

As @mckenzm had pointed out the approach of dumping the contents of the archive into the in-path folders like /usr/local/bin/ is not a great one. You will be in a lot of trouble when you have to remove this and upgrade to the next version due to some security issue.

The following are two approaches to follow

Manual installation

The approach to follow is to keep it in a way that it is easy to remove and upgrade, the way to do it is to keep all the stuff in one place and add that place to your path, for that One can do

sudo tar -xf node-v20.11.0-linux-x64.tar.xz --directory=/opt/

and add the bin folder to your $PATH variable using the following

echo 'export PATH="/opt/node-v20.11.0-linux-x64/bin/:$PATH"' >> ~/.bashrc && source ~/.bashrc

This is a better approach because you can remove it, and upgrade it easily compared to just dumping all the files in the /bin folder, like many, including my previously written answer ( deleted now ), are telling.

Now on any given day, you can remove the entire folder from /opt and replace it with the version you want or even you can use multiple versions at the same time.

Using tools like nvm

node version manager is a tool, that can be very useful, specially for personal use, when you might need more than one version, you can install it via reading the documentation - it is very simple to do and nvm is a very useful script - for more visit https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script

If you ask me, I prefer the nvm approach.

Top answer
1 of 2
31

If you want to install and switch between multiple versions of node then nvm (Node.js version manager) is better option.

  1. Check whether you have nvm or not. If not then you can pull down the nvm installation script from the project's GitHub page. The version number may be different, but in general, you can download it with curl:

    curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
    

    Run the script with bash:

    bash install_nvm.sh
    

    It will install the software into a subdirectory of your home directory at ~/.nvm. It will also add the necessary lines to your ~/.profile file to use the file.

    To gain access to the nvm functionality, you'll need to log out and log back in again, or you can source the ~/.profile file so that your current session knows about the changes:

    source ~/.profile
    

  1. If you have multiple Node.js versions, you can see what is installed by typing:

    nvm ls
    
  2. You can install your specific node version by typing:

    nvm install 6.7.0
    
  3. If you wish to default one of the versions, you can type:

    nvm alias default 6.7.0
    
  4. Now you can also reference it by the alias like this:

    nvm use default
    
  5. Check now node version to verify whether changes are made or not by typing:

    node -v
    
2 of 2
9

If you only want to install tar.xz file from nodejs.org then follow below answer.

Try below links that might help you.

  1. Install NodeJS NPM on Linux

    if your downloaded NODE-LTS file is in *.tar.xz format, then replace:

    tar --strip-components 1 -xzf /usr/save/node-v4.2.1-linux-x64.tar.gz
    

    with

    tar --strip-components 1 -xf /usr/save/node-v4.2.1-linux-x64.tar.xz
    
  2. If the above method does not work, then follow this guide.


If these answers do not work, there is another way that works by using nvm. This method is specified in another answer.

🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
Need help installing Node.js (tar.xz) - Linux Mint Forums
tar -xvf 'node-v16.13.1-linux-... Failing that, Node.JS is already in the Ubuntu (therefore Linux Mint) repositories, so you can just: sudo apt-get install nodejs...
🌐
GitHub
gist.github.com › developeryashraj › 14fd206668936d1e9be2b818bf8b0be2
Installing Node on Ubuntu using tar.xz binary · GitHub
Clone this repository at <script ... node. Do change file name with your downloaded file. sudo tar -C /usr/local --strip-components 1 -xf node-v8.11.4-linux-x64.tar.xz...
🌐
GoLinuxCloud
golinuxcloud.com › home › ubuntu › how to install node.js on ubuntu from tar.xz? [solved]
How to install Node.js on Ubuntu from tar.xz? [SOLVED] | GoLinuxCloud
November 28, 2022 - The recommended version on the Node.js official website is 18.12.1 LTS. Go to its official address, right click on the download link and copy the link. 19.1.0 is available in the latest version at the same address.
🌐
GitHub
github.com › quraishi12 › How-to-Install-Node.js-from-node.tar.xz-in-Linux
GitHub - quraishi12/How-to-Install-Node.js-from-node.tar.xz-in-Linux
Latest Version of Node: Steps to Download and Install Node in Ubuntu Linux Step 1: Download Latest Version · Download the latest version of the node.tar.xz file from the official website: [Node.js Official Website] Step 2: Navigate to Download ...
Author   quraishi12
Find elsewhere
🌐
YouTube
youtube.com › watch
Install NodeJS tar.xz on Ubuntu - YouTube
Here I'm showing a simple method on how to install NodeJS setup file downloaded from nodejs.org website.Command I used as follows:sudo cp -r node/{bin,includ...
Published   November 18, 2016
🌐
YouTube
youtube.com › study read educate
How to Install Node.js in Ubuntu Using tar file - YouTube
Learn how to install node.js by using tar file in Ubuntu or linux.#nodejs #linux #ubuntu #ubuntunodejs
Published   September 25, 2019
Views   20K
🌐
YouTube
youtube.com › neurons
Install nodejs via binary archive (.tar.xz file) on Ubuntu 21.10 - YouTube
how to install node.js via binary archive (.tar.xz archive file) on ubuntu 21.10. #lumafusion #ubuntu #linux #webdevelopment #nodejs #npm
Published   October 25, 2021
Views   12K
🌐
Muhammetkucuk
muhammetkucuk.com › install-node-js-from-linux-tar-gz-file
Install Node.js from linux tar.gz file – Muhammet Küçük
wget https://nodejs.org/dist/v12.13.1/node-v12.13.1-linux-x64.tar.gz sudo tar -C /usr/local --strip-components 1 -xzf node-v12.13.1-linux-x64.tar.gz #To verify our installation: node --version · If node.js’s website directs you to tar.xz file, change url with tar.gz.
🌐
Netveloper
netveloper.com › instalar-nodejs-desde-un-fichero-.tar.xz-en-linux
Instalar nodejs desde un fichero .tar.xz en Linux
cd /opt sudo tar xvf node-v14.15.0-linux-x64.tar.xz Ahora ya lo tenemos instalado y Si entramos en el directorio /opt/node-v14.15.0-linux-x64/bin podemos ver que tenemos un fichero llamado node y unos enlaces simbólicos, si ejecutamos el comando ...
🌐
Linux.org
linux.org › home › forums › general linux forums › ask tuxbot (archived)
help installing nodejs | Linux.org
February 15, 2024 - That way, you'll get the latest stable release and all the dependencies. But if you really want to use the tarball, here's how you can do it: 1. Download the tarball from the official Node.js website.
🌐
Medium
medium.com › @rabbi.cse.sust.bd › install-nodejs-via-binary-archive-on-ubuntu-18-04-63118473d9e9
Install NodeJS via binary archive on Ubuntu 18.04 | by Md. Mehedi Hasan | Medium
May 20, 2019 - node-v10.1.0-linux-x64.tar.xz · ... command for read/write permission: sudo chmod -R 755 ./ Extract archived binary via: tar xf node-v10.1.0-linux-x64.tar.xz ·...