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
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
I got it installed with the below command. Don't include curly braces in the command. I place it in the command just for readability. You have to change the download-directory and filename according to your preference.
sudo tar --strip-components 1 -xvf {download-directory}/{filename}.tar.xz --directory /usr/local/
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
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.
If you want to install and switch between multiple versions of node then nvm (Node.js version manager) is better option.
Check whether you have
nvmor 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 withcurl:curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.shRun the script with bash:
bash install_nvm.shIt will install the software into a subdirectory of your home directory at
~/.nvm. It will also add the necessary lines to your~/.profilefile 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
~/.profilefile so that your current session knows about the changes:source ~/.profile
If you have multiple Node.js versions, you can see what is installed by typing:
nvm lsYou can install your specific node version by typing:
nvm install 6.7.0If you wish to default one of the versions, you can type:
nvm alias default 6.7.0Now you can also reference it by the alias like this:
nvm use defaultCheck now node version to verify whether changes are made or not by typing:
node -v
If you only want to install tar.xz file from nodejs.org then follow below answer.
Try below links that might help you.
Install NodeJS NPM on Linux
if your downloaded
NODE-LTSfile is in*.tar.xzformat, then replace:tar --strip-components 1 -xzf /usr/save/node-v4.2.1-linux-x64.tar.gzwith
tar --strip-components 1 -xf /usr/save/node-v4.2.1-linux-x64.tar.xzIf 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.
According to the official website you can install node-v6.x as follow:
sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
Install Node.js (node-v6.9.4-linux-x64.tar.xz)
Download and extract the Node.js "Linux Binaries" package. For example, if you downloaded version 6.9.4 for 64-bit you could install Node.js into /opt:
cd /opt
tar -Jxf node-v6.9.4-linux-x64.tar.xz
Set PATH to include Node.js:
export PATH=/opt/node-v6.9.4-linux-x64/bin:$PATH