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
Answer from Nullpointer on Stack Overflow
» npm install node-tar.gz
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.
Videos
» npm install targz
I solved it by creating stream as below.
var req = http.request(options, function(res) {
var body = '';
var file = fs.createWriteStream('./test4.tar.gz');
res.on('data', function(chunk){
file.write(chunk);
}).on('end', function(){
file.end();
});
});
req.write(postData);
req.end();
why don't you use the application/gzip content type ? I believe your issue come from there.
» npm install tar.gz
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.
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/
» npm install tar
» npm install download-package-tarball
For anyone interested in the answer, it is possible using streams and the module tar-stream. Here is a complete example that extracts a file called documents.json from the archive archive.tar.gz:
var tar = require('tar-stream');
var fs = require('fs');
var zlib = require('zlib');
var extract = tar.extract();
var data = '';
extract.on('entry', function(header, stream, cb) {
stream.on('data', function(chunk) {
if (header.name == 'documents.json')
data += chunk;
});
stream.on('end', function() {
cb();
});
stream.resume();
});
extract.on('finish', function() {
fs.writeFile('documents.json', data);
});
fs.createReadStream('archive.tar.gz')
.pipe(zlib.createGunzip())
.pipe(extract);
This is old, but Gianni's solution didn't quite work for me, maybe because he was extracting text files, I'm not sure.
Also, you can optimize quite a bit by only checking the header name once instead of for every data chunk for every file record.
var tar = require('tar-stream');
var fs = require('fs');
var zlib = require('zlib');
var extract = tar.extract();
var chunks = [];
extract.on('entry', function(header, stream, next) {
if (header.name == 'documents.bin') {
stream.on('data', function(chunk) {
chunks.push(chunk);
});
}
stream.on('end', function() {
next();
});
stream.resume();
});
extract.on('finish', function() {
if (chunks.length) {
var data = Buffer.concat(chunks);
fs.writeFile('documents.bin', data);
}
});
fs.createReadStream('archive.tar.gz')
.pipe(zlib.createGunzip())
.pipe(extract);