In the previous article, we have learned what is Node.js and the logic behind all those fancy Node.js concepts for beginners.
In this article, we will learn how to decide the most suitable Node.js version for you and install/uninstall it on your Debian based Linux machine. Through this article, I tested installation/uninstallation on Ubuntu 18.04 and Linux Mint 19.1.
First, let’s start with Node.js in terms of deciding which version we should use.
If you visit the https://nodejs.org website, you will see two different Node.js versions as “Recommended For Most Users” version option and “Latest Features” version option.
When this article is written, “Recommended For Most Users” version is 12.13.0 LTS and “Latest Features” version is 13.0.1 Latest Features (Current). You might confuse a little bit about those LTS and Latest Features (Current) words.
As a general term in software development, LTS stands for long-term support which indicates the LTS version of the developed/developing software is still maintaining for a longer period of time than other versions. Maintaining software means that we can have security updates, bug fixes, minor feature upgrades in a given period of time of LTS.
So what about other versions? Why are they developing other versions too?
Latest Features (Current) Version
Latest Features (Current) version is being developed because without affecting the stable production environments and spooking the legacy users, it is not so possible to build high-end features. Thanks to that we can have major performance improvements, extra additional functionalities, architectural changes.
At the end of the Latest Features version development cycle, its codebase will be moved to the next LTS version with all changes and improvements. So it will become a more stable and secure environment to use.
That is why in Node.js community, “Recommended For Most Users” is most suitable for the production environment and “Latest Features” is for experimenting latest Node.js features. But at the end of the day, we know that the latest features will be added to the next LTS version.
In order to review Node.js releases, you can check this URL: https://nodejs.org/en/about/releases/
From their graph, you can easily understand that even-numbered versions are LTS versions and odd-numbered ones are the latest feature versions. Also, you can see their end of development dates and maintenance durations for each different version.
Now we can decide which Node.js version we should choose and start the installation right away. I assume that we need to build a secure and stable application thus we can choose the current LTS version 12.13.0.
Node.js Installer and Source
From Node.js community website download page link https://nodejs.org/en/download/current/, you can see that it can work any Windows, Mac OS, or Linux machine. You have two options to install on your machine as you can download its installer or you can build it from its source code. Also, you have an option to run on a docker container with its docker image but unfourtunalety this article is not covering docker containers.
Curious ones that don’t know about package managers may ask: “Why do we need package managers?”
In the past, it was not easy to manage software dependencies (third-party libraries).
You had to add every dependency codebase into your codebase which makes yours heavier to store and move along other machines. Also, the dependencies might have other dependencies and this can go in a recursive way. This problem may result in bigger problems in the future if we want to update, change or remove any dependency.
After a quick break lets continue with the installation/uninstallation process. But before starting the installation, please first check whether you have installed Node.js or npm already. Because lots of frameworks are using Node.js as their infrastructure. So you might be installed Node.js without knowing it.
Node.js and npm Version Check
The most common way to check is Node.js and npm is installed or not is by checking their versions:
Sample output will be if you have already installed Node.js:
But we don’t want this Node.js version. So let’s remove it:
As a common approach, you can remove Node.js and its configuration files with purge:
$sudo apt purge nodejs
But sometimes you still can not get rid of from installed Node.js and npm. As a solution first detect their installation folders and remove them directly. For detection:
Now you know where they are installed. Just remove them:
$sudo rm /usr/local/bin/node
$sudo rm /usr/local/bin/npm
If you check Node.js and npm is whether installed or not:
You can get this output if you have never installed Node.js too.
After we ensured that we don’t have Node.js or npm installed on our system, we can start the installation process.
The first easiest approach to install any package to your Debian based machine can be:
$sudo apt update
$sudo apt install nodejs
$sudo apt install npm
You need to install npm separately because Node.js package is not coming with npm for this specific case. Then check the installed Node.js and npm versions:
As you can see both Node.js and npm versions are outdated. Because when we use apt to install packages, by default we are using Universe repositories. These repositories may not be up to date all the time.
In order to install the latest desired Node.js and npm version, we need to use PPA (Personal Package Archive) of the Node.js community thanks to NodeSource (https://github.com/nodesource/distributions/blob/master/README.md). Basically add the desired repository to your Linux package sources then start the same installation process.
$curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
$sudo apt-get install -y nodejs
If you want to install the 13.^ version (Latest Features) of Node.js, you can simply change it to:
$curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash - $sudo apt-get install -y nodejs
We have just installed Node.js and npm all together. Please note that by using this PPA, we don’t need to install npm separately and deal with its version.
You can see from https://nodejs.org/en/download/releases/, each Node.js versions have their specific npm version to compatible with. That is why it is really helpful to install Node.js through PPA.
After the installation, you can check the installed version of Node.js and npm as
As you can see now we have installed the desired Node.js on our Linux machine.
Let’s try our Node.js environment in two different ways.
Then in order to run it:
You can check which Ecma Script version and features are supported in your Node.js version from https://node.green. As you can see 12.13.0 is already covering most of the ES2020 features.
I hope this article has helped you in terms of understanding Node.js versions and installation/uninstallation on your Debian based Linux machine. Also, if you feel uncomfortable about some topics of Node.js, I really encourage you to read Node.js Explained for Beginners article.
If you want to learn more about Web Development, don’t forget to subscribe to our newsletter and if you have any questions, please don’t hesitate to contact with me.
See you in new articles.
Hello, I am Bahadır, a passionate full-stack web developer. I am not afraid to get my hands dirty while creating software projects. I love my job which is mostly developing web applications by using Node.js, PHP, Smarty, jQuery, MySQL, MongoDB, Redis and hosting them on AWS. Also, I have an MSc degree in Computer Engineering Department of İzmir Institute of Technology whose thesis work is about the field of Machine Learning.