“How to Install Node.js” and “npm” on “Ubuntu 20.04”

Maneesh kushwaha
5 min readJun 2, 2020

--

“How to Install Node.js” and “npm” on “Ubuntu 20.04”

June 2, 2020 by Editorial Staff

“How to Install Node.js” and “npm” on “Ubuntu 20.04”

Contents [like]

“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 surroundings 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 in style 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 are going to discover three alternative ways of putting in Node.js and npm on Ubuntu 20.04:

  • From the usual Ubuntu repositories. That is the best strategy to set up Node.js and npm on Ubuntu and ought to be adequate for many use instances. 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 special Node.js model than the one supplied within the Ubuntu repositories. At present, NodeSource helps Node.js v14.x, v13.x, v12.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 methodology that’s acceptable on your surroundings. If you’re unsure 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 easy. 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 plenty of packages, together with the instruments essential to compile and set up native addons from npm.

As soon as carried out, confirm the set up by operating:

nodejs --versionv10.19.0

Installing Node.js and npm from NodeSource #

NodeSource is an organization targeted on offering enterprise-grade Node help. 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 steady model.
  • v13.x
  • v12.x — The newest LTS model.
  • v10.x — The earlier LTS model.

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

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

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

The script will add the NodeSource signing key to your system, create an apt repository file, set up all obligatory packages, and refresh the apt cache. For those who want one other Node.js model, for instance 12.x, change the setup_14.x with setup_12.x.

As soon as the NodeSource repository is enabled, set up Node.js and npm:

sudo apt install nodejs

The nodejs package contains both the node and npm binaries.

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

node --version v14.2.0 npm --version 6.14.4

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 simply need to use or take a look at.

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

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | 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.sh" ] && . "$NVM_DIR/nvm.sh" # 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 --version0.35.3

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 --versionv14.2.0

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
v12.16.3
v14.2.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 precise (> v10.9.0) is the Node.js model used within the present shell session and the default model is ready to v14.2.0. Default model is the model that will likely be energetic when opening new shells.

If you wish to change the presently energetic model enter:

nvm use 12.16.3Now 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 methods to use the nvm script, go to the venture’s GitHub web page.

Conclusion

We’ve got 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. Although putting in the packaged model from the Ubuntu or NodeSource repository is simpler, the nvm methodology provides you extra flexibility for including and eradicating totally different Node.js variations on a per-user foundation.

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 Install Ruby

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response