How to Install Node.js and npm on Ubuntu 20.04 - MS TV Life.COM

How to Install Node.js and npm on Ubuntu 20.04

How to Install Node.js and npm on Ubuntu 20.04

We hope this post helped you to find out  How to Install Node.js and npm on Ubuntu 20.04

Node.js is a cross-platform JavaScript runtime atmosphere constructed on Chrome’s JavaScript, designed to execute JavaScript code on the server-side. It’s typically used to construct back-end purposes, however it is usually well-liked as a full-stack and front-end answer. npm is the default bundle supervisor for Node.js and the world’s largest software program registry.

On this tutorial, we’ll discover three alternative ways of putting in Node.js and npm on Ubuntu 20.04:

  • From the usual Ubuntu repositories. That is the best option to set up Node.js and npm on Ubuntu and needs to be enough for many use circumstances. The model included within the Ubuntu repositories is 10.19.0.
  • From the NodeSource repository. Use this repository if you wish to set up a distinct Node.js model than the one offered within the Ubuntu repositories. At the moment, NodeSource helps Node.js v14.xv13.xv12.x, and v10.x.
  • Utilizing nvm (Node Model Supervisor). This device lets you have a number of Node.js variations put in on the identical machine. If you’re Node.js developer, then that is the popular manner of putting in Node.js.

Select the set up technique that’s applicable to your atmosphere. If you’re undecided which Node.js model to put in, seek the advice of the documentation of the applying you’re going to deploy.

Set up Node.js and npm from the Ubuntu repository #

On the time of writing, the Node.js model included within the Ubuntu 20.04 repositories is 10.19.0 which is the earlier TLS model.

The set up is fairly simple. Run the next instructions to replace the bundle index and set up Node.js and npm:

sudo apt update
sudo apt install nodejs npm

The command above will set up a variety of packages, together with the instruments essential to compile and set up native addons from npm.

As soon as finished, confirm the set up by working:

nodejs --version

Installing Node.js and npm from NodeSource #

NodeSource is an organization targeted on offering enterprise-grade Node assist. It maintains an APT repository containing a number of Node.js variations. Use this repository in case your utility requires a selected model of Node.js.

On the time of writing, NodeSource repository supplies the next variations:

  • v14.x – The newest secure model.
  • v13.x
  • v12.x – The newest LTS model.
  • v10.x – The earlier LTS model.

We’ll set up Node.js model 14.x:

Stop 1. Run the next command as a person with sudo privileges to obtain and execute the NodeSource set up script:

curl -sL | sudo -E bash -

The script will add the NodeSource signing key to your system, create an apt repository file, install all necessary packages, and refresh the apt cache. If you need another Node.js version, for example 12.x, change the setup_14.x with setup_12.x.

Stop 2. Once the NodeSource repository is enabled, install Node.js and npm:

sudo apt install nodejs 

The nodejs package contains both the node and npm binaries.

Stop 3. Verify that the Node.js and npm were successfully installed by printing their versions:

node --version
 npm --version 

To be able to compile native addons from npm you’ll need to install the development tools:

sudo apt install build-essential

Installing Node.js and npm using NVM #

NVM (Node Model Supervisor) is a bash script that lets you handle a number of Node.js variations on a per-user foundation. With NVM you’ll be able to set up and uninstall any Node.js model that you just wish to use or take a look at.

Go to the nvm GitHub repository web page and replica both the curl or wget command to obtain and set up the nvm script:

curl -o- | bash

Do not use sudo as it will enable nvm for the root user.

The script will clone the project’s repository from Github to the ~/.nvm directory:

=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && . "$NVM_DIR/"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Because the output above says, it’s best to both shut and reopen the terminal or run the instructions so as to add the trail to nvm script to the present shell session. You are able to do no matter is simpler for you.

As soon as the script is in your PATH, confirm that nvm was correctly put in by typing:

nvm --version

To get a list of all Node.js versions that can be installed with nvm, run:

nvm list-remote

The command will print a huge list of all available Node.js versions.

To install the latest available version of Node.js, run:

nvm install node

The output should look something like this:

Checksums matched!
Now using node v14.2.0 (npm v6.14.4)
Creating default alias: default -> node (-> v14.2.0)

Once the installation is completed, verify it by printing the Node.js version:

node --version

Let’s install two more versions, the latest LTS version and version 10.9.0:

nvm install --ltsnvm install 10.9.0

You can list the installed Node.js versions by typing:

nvm ls

The output should look something like this:

>      v10.9.0
default -> node (-> v14.2.0)
node -> stable (-> v14.2.0) (default)
stable -> 14.2 (-> v14.2.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/erbium (-> v12.16.3)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.20.1 (-> N/A)
lts/erbium -> v12.16.3

The entry with an arrow on the best (> v10.9.0) is the Node.js model used within the present shell session and the default model is about to v14.2.0. Default model is the model that can be lively when opening new shells.

If you wish to change the presently lively model enter:

nvm use 12.16.3
Now using node v12.16.3 (npm v6.14.4)

To change the default Node.js version, run the following command:

nvm alias default 12.16.3

For extra detailed details about how one can use the nvm script, go to the venture’s GitHub web page.

Conclusion #

We’ve proven you three alternative ways to put in Node.js and npm in your Ubuntu 20.04 server. The strategy you select is determined by your necessities and preferences. Regardless that putting in the packaged model from the Ubuntu or NodeSource repository is simpler, the nvm technique offers you extra flexibility for including and eradicating completely different Node.js variations on a per-user foundation.

How to Install Go on Ubuntu 20.04

We hope the How to Install Node.js and npm on Ubuntu 20.04 help you. If you have any query regarding How to Install Node.js and npm on Ubuntu 20.04 drop a comment below and we will get back to you at the earliest.

We hope this post helped you to find out  How to Install Node.js and npm on Ubuntu 20.04  . You may also want to see – How to Set Up a Firewall with UFW on Ubuntu 20.04


Copy link
Powered by Social Snap