Personal Log 2020-11-21
This post explains how I upgrade node and npm on my Ubuntu machine. I used these steps to generate a custom script that can replace my existing node/npm installation with the new version.
You can use the file command to verify the file type matches the extension.
🖥️ file node-v14.15.1-linux-x64.tar.xz
📟 node-v14.15.1-linux-x64.tar.xz: XZ compressed data
The tar extract tool can be used to extract .tar.gz and .tar.xz files. The -z flag is only needed for tar files of the gz (gzip) variety. If you try to extract the xz variety with the -z flag, you will get this error message:
🖥️ tar -xzvf node-v14.15.1-linux-x64.tar.xz
📟 gzip: stdin: not in gzip format
📟 tar: Child returned status 1
📟 tar: Error is not recoverable: exiting now
I searched Stack Overflow for a way to remove the file extension using bash, since the new folder name is the same as the file, minus the extension. In this case, I needed two .* to remove both .xz and .tar.
🖥️ newPackage="node-v14.15.1-linux-x64.tar.xz"
🖥️ newFolder="${newPackage%.*.*}"
🖥️ cd $newFolder
Since my installation is in the /usr/local directory (which is owned by root), I needed to use sudo to move files to and delete files from this location.
🖥️ installFolder="/usr/local"
Execute using sudo from newFolder (in no particular order):
🖥️ mv bin/* $installFolder/bin
🖥️ rm -rf $installFolder/lib/node_modules
🖥️ mv lib/node_modules/ $installFolder/lib
🖥️ rm -rf $installFolder/share/doc/node
🖥️ mv share/doc/node $installFolder/share/doc
🖥️ rm -rf $installFolder/share/man/man1
🖥️ mv share/man/man1 $installFolder/share/man
🖥️ mv share/systemtap/tapset/node.stp $installFolder/share/systemtap/tapset
🖥️ rm -rf $installFolder/include/node
🖥️ mv include/node $installFolder/include
Once the files have been transferred, check the remaining content of the extracted folder to verify that no other files are present. Delete the remaining content of the extracted folder, and check the new versions of node and npm are correct:
🖥️ node --version
📟 v14.15.1
🖥️ npm --version
📟 6.14.8