Thursday, December 19, 2019

software installation - How does tar command work for installing Node js



When installing Node on my machine, I used the below command that I found on a website.



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



I know that tar -xzf is used to extract the archives but I want to know how is node getting installed?



I tried installing it in this way. I've extracted the node files to /usr/local using the below command,



tar /usr/local -xzf /usr/save/node-v4.2.1-linux-x64.tar.gz


But this doesn't work. Can somebody explain or help me to understand the difference between these two commands?



What more is command 1 doing than what command 2 is doing?




The tarball directory structure is like this:



$ tar tf node-v6.10.1-linux-x64.tar.xz | head
node-v6.10.1-linux-x64/
node-v6.10.1-linux-x64/bin/
node-v6.10.1-linux-x64/bin/npm
node-v6.10.1-linux-x64/bin/node
node-v6.10.1-linux-x64/share/
node-v6.10.1-linux-x64/share/man/

node-v6.10.1-linux-x64/share/man/man1/
node-v6.10.1-linux-x64/share/man/man1/node.1
node-v6.10.1-linux-x64/share/systemtap/
node-v6.10.1-linux-x64/share/systemtap/tapset/


When you extract this archive without any other options in /usr/local, you get this:



/usr/local/node-v6.10.1-linux-x64/
/usr/local/node-v6.10.1-linux-x64/bin/

/usr/local/node-v6.10.1-linux-x64/bin/npm
/usr/local/node-v6.10.1-linux-x64/bin/node
/usr/local/node-v6.10.1-linux-x64/share/
/usr/local/node-v6.10.1-linux-x64/share/man/
/usr/local/node-v6.10.1-linux-x64/share/man/man1/
/usr/local/node-v6.10.1-linux-x64/share/man/man1/node.1
/usr/local/node-v6.10.1-linux-x64/share/systemtap/
/usr/local/node-v6.10.1-linux-x64/share/systemtap/tapset/



So, a new directory is created in /usr/local, and the files get dumped there.



However, with --strip-components=1, one directory component from the extracted path is removed, so node-v6.10.1-linux-x64/bin/ becomes bin/ and node-v6.10.1-linux-x64/bin/npm becomes bin/npm:



/usr/local/
/usr/local/bin/
/usr/local/bin/npm
/usr/local/bin/node
/usr/local/share/
/usr/local/share/man/

/usr/local/share/man/man1/
/usr/local/share/man/man1/node.1
/usr/local/share/systemtap/
/usr/local/share/systemtap/tapset/


And /usr/local/bin is already in PATH, so you don't need to do anything else to execute npm and node.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...