Home > Categories > Ubuntu > Install or Update Nodejs in Ubuntu
Home > Install or Update Nodejs in Ubuntu
Install or Update Nodejs in Ubuntu
Updated:
Published:
When you use package managers then it automatically download the dependencies.
Lot's of packages require current version of nodejs not the LTS version of nodejs.
Many times current version is not stable and fails. I was stuck with non working version of nodejs.
And reinstalling nodejs didn't fix the problem. So I decided to install nodejs manually and learn adding path. I hope other people find it helpful.
To read rest of the article please Purchase Subscription
First step is to create new folder with any name of your choice. This is where you download/extract/build packages.
So in case you mess things up and extract 3000 random files then you can just delete the whole folder and not mess with your existing files.
I always name it download. The name is based on download folder used in either Windows or macOS.
mkdir download
cd download
Now go to official nodejs download page.
Don't click on link but instead right click and copy the link url.
Choose the link based on version, your operating system and processor(arm/x86).
wget insert_download_url_here
wget https://nodejs.org/dist/insert_target_node_version_here/SHASUMS256.txt
sha256sum -c SHASUMS256.TXT
For example
wget https://nodejs.org/dist/v14.15.1/node-v14.15.1-linux-arm64.tar.xz
wget https://nodejs.org/dist/v14.15.1/SHASUMS256.txt
sha256sum -c SHASUMS256.TXT
Just insert version number and download the checksum file.
And to verify checksum put the above command and you should see lot of error message. But look for file name and ok as follows
sha256sum: node-v14.15.1-linux-arm64.tar.gz: No such file or directory
node-v14.15.1-linux-arm64.tar.gz: FAILED open or read
node-v14.15.1-linux-arm64.tar.xz: OK
Now simply extract the compressed file. With one of 2 ways.
|
|
-x
= Extract
-f
= Specified file name
-C
= Output directory. The output directory must exist before extracting.
The complex version will remove the extracted folder and put its content inside nodejs folder.
Then move the extracted folder
sudo mv nodejs/ /usr/local/lib/
Then you need to add nodejs path
vi ~/.profile
Add following at the bottom of the profile
|
|
Then refresh profile and check node version
. ~/.profile
node -v
npm -v
For updating the steps are exactly the same except you don't have to add the path.
You delete previous nodejs folder and replace with new one.
Important This method will delete all globally installed npm packages so you will need to install global packages again.
Free users cannot comment below so if you have questions then tweet me @apoorvmote. I would really like to hear your brutally honest feedback.
If you like this article please consider purchasing paid