How to install the latest LTS version of "NodeJS" in "LINUX"?
Roshan Khetpal
Posted on April 7, 2024
Intro :)
Hello everyone, I hope you're all doing well๐.
In this blog post, we will learn "how you can install the latest LTS version of NodeJS on your Linux machine." As we know, if you try to install Node.js using the Linux package manager, sudo apt install nodejs
or sudo nala install nodejs
based on your distro. After running this command, you will obtain an outdated version of Node.js.
The issue may be caused by outdated package repositories or distros. In order to fix the issue, we must manually download & configure Node.js by adding it to the environment path variable.
Purging old version of Node.js๐
Before moving ahead, if you have an older version of Node.js installed, then make sure to purge (remove) it using these commands.
$ sudo apt purge node.js
After this, run this command to delete all the config files.
$ sudo apt autoremove
Installation โฌ
Step 1: Checking the system's architecture.
Check your system's architecture by simply running the following command:
$ arch
or
$ uname -m
Step 2: Downloading.
Head over to the Node.js official website and follow these steps to download. The Node.js website has undergone a significant redesign, making it more visually appealing and easier to navigate.๐๐
Step 3: Extracting the archive Node.js file.
After clicking on the download button, you'll get an archive file, and extract the Node.js archive file.
Rename the folder from node-v20.12.1-linux-x64
to nodejs
or something as per your convenience.
Step 4: Renaming the folder to nodejs
& Moving nodejs
folder to /home
dir.
This step is not mandatory, but it is recommended that you follow it.
Move nodejs
folder to your ๐ Home
directory by running the following command inside that folder.
$ mv nodejs/ /home/user
Step 5: Setting up the path variable.
So, we're at the last step, setting up the path variable to access the Node.js command from anywhere, just like Windows.
To set up the path variable, you need to navigate inside the nodejs
folder.
/home/user/nodejs/bin
As you can see, we've got npm, node, and npx
, all the necessary packages.
Now copy the path of this 'bin'
folder. You can copy from the properties of this bin
folder.
Now, open your bashrc
configuration file using the following commands:
sudo gedit ~/.bashrc
or if you're using zsh shell
sudo gedit ~/.zshrc
After opening bashrc
or zshrc
configuration file, copy and paste the following line at the very bottom, and save the file.
export PATH=$PATH:/home/(Your Username)/nodejs/bin
Voila!! Node.js has been updated, and you're all set to use the latest version now.
To check the version using your terminal, close it and open it again. Then, run the necessary commands to verify the version.
node -v
Outro ๐ธ
I understand that installing software can be a bit tricky in Linux at times, but I sincerely hope that you were able to install the latest LTS version of Node.js on your Linux machine. Let me know if you need any further assistance with anything else.
Resources used in article: Node.js | Oh My Zsh for zsh customization
Are you following me on social media:)?
All my social links are here ๐ https://linktr.ee/roshankhetpal
Posted on April 7, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.