How to install the latest LTS version of "NodeJS" in "LINUX"?
Tags: javascript, webdev, linux, node
Published: 2024-04-07 04:30:00

## 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.

![Node.js Vs. Linux gaddari karbe](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vbrxwzjhw8mznw2vssr.png)

---

## 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`

![Node.js Version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3kabhz2gi03x9llmgit2.png)

### Step 2: Downloading.

Head over to the [Node.js](https://nodejs.org/en/download/prebuilt-binaries) 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.👇👇

![Node.js downlaod](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n8u9913pskct7t1eiihm.gif)

### 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.

![File Extraction](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r40uu6xzbewk8ni4sq5w.png)

### 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`

![Moving nodejs folder to home](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rvpv33g3y7967oc6q5c8.png)

### Step 5: Setting up the path variable.

So, we're at the last step, setting up the <mark>path variable</mark> 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`

![Nodejs bin folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0p6eqz2w9og2q8ea8qu.png)

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.

![Node path copy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hhmh7ppoqewxpbnfsx3j.png)

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`

![Editing bashrc](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1l4mgg81urtg7ohg3l7.png)

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`

![Node updated version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/onisrlil2pl61i5nsvu1.png)


![Here you go.gif](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1tr8yiu6yi877twjtab7.gif)

## 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](https://nodejs.org/en/download/prebuilt-binaries) | [Oh My Zsh for zsh customization](https://ohmyz.sh/)

Are you following me on social media:)?

**All my social links are here** 👉 [https://linktr.ee/roshankhetpal](https://linktr.ee/roshankhetpal)