What is Node.JS?
Node.js comes with in-built support for managing the package with the help of npm (Node Package Manager). NPM is one of the important package libraries offering various features. You can use its vast downloadable libraries, and it is available free of cost. Day by day, these libraries are getting bigger, making Node.js stronger and better.
You can install Node.js on Debian/Ubuntu and many other platforms. We highlight the simple steps to install Node.js on the Debian 20.04 system; read below and follow for error-free installation!
Advantages of Using Node.JS
Below are few advantages of using Node.js:
- It comes with a npm package, providing a wide variety of features.
- It has wide community support, actively managing Node.js.
- It helps in streaming files of big size.
- It is based on asynchronous event-driven IO, which helps in managing concurrent requests.
Disadvantages of using Node.js
Below are a few disadvantages of using Node.js:
- You will not be able to scale using Node.js. Using Node.js, working with one CPU is not enough. Also, you will not be able to avail benefits of several cores present in server-class hardware.
- If you are using callback features, you may enter a loop of callbacks.
- Node.js is not well-suited for CPU-intensive work.
Installing NodeJS on Ubuntu 20.04
Here, we will pinpoint the three different ways for installing the Node.js on Ubuntu 20.04 server.
You can install the Node.js package with the help of apt from Ubuntu’s default software repository.
You can install a specific version of the Node.js package with the help of an apt using an alternate PPA software repository.
You can install the Node.js package via Node Version Manager and managing various versions of Node.js.
Below are the basic prerequisites for installing the node.js package on Ubuntu 20.04 server.
Set up the Ubuntu 20.04 server on your system.
Users should have a non-root user account, but especially with the admin rights for running various commands.
Method 1: Using Apt from the Default Repository
The default repository of Ubuntu 20.04 comes with a Node.js version, providing a consistent experience for all systems. We have the repository version as 10.19. If you want to get this version, you can use the apt package manager. Then, refresh your local package index first by running the below command.
Now, start installing Node.js by running the below command in the terminal.
After running the command mentioned above successfully, run the below command for checking the version of the installed Node.js.
More packages other than the default one can be installed accordingly. Apart from the default repositories, you will require npm (Node.js package manager). You can run this command line command to start the installation of the npm package with apt.
After running the above commands, you have successfully installed Node.js and npm using apt.
Method 2: Using Apt Using a NodeSource PPA
To install the various versions of Node.js, use the NodeSource PPA (personal package archive). You will get more versions available for Node.js, as you can find in the Ubuntu repository. With time, you will get a new version added to the list.
Before accessing the packages, install PPA. Use “curl” from the home directory to get the script for installing your choice of Node.js version. We are using the 14.x version in the below command, and you can replace it with whatever version you want to install.
$ curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
Use a nano text editor to check the downloaded script content. Then, simply run the below-mentioned command from the terminal to do so.
Next, exit the editor after checking and verifying the script’s content and run the below sudo command to run the script.
After running the commands mentioned above, you will automatically add the PPA to your configuration and update the local package cache.
Now, run the below command for installing the Node.js package.
After the successful installation of npm, you will be able to check the installed version of Node.js using the below-mentioned command.
The node js package from the NodeSource comes with both the node binary and npm. So, do not install the npm package explicitly.
Method 3: Using Node Version Manager
Using nvm (Node version manager), you can install and maintain several independent Node.js versions and their node packages altogether. Install the NVM using the curl command from the README file available on the main page. In addition, avail the installation script of the latest version.
Before running the command, verify its content. For example, run the below command to check the content.
Once you confirm the script, you can run the below command with a bash at the end to download and execute the script.
The above command will install the nvm script to your user account. For using the script, add the source to your .bashrc file, as shown below.
To check the NVM for available Node.js versions, you can run the below command.
For example, if you want to install Node.js from the available versions, run the below command.
After successfully installing the Node.js version, run the below command for checking the installed version.
We have mentioned and discussed three different ways for installing Node.js and npm on your Ubuntu 20.04 server. Of course, you can go with any of the mentioned methods depending on your requirements and preferences. However, installing the packaged version using the NodeSource repository is easier. Apart from this, you will get enhanced flexibility by using the nvm method for adding and removing different Node.js versions on a per-user basis.
Now that you’ve installed Node.js on your Ubuntu 20.04 system, go ahead and develop your application!