How to install Node.js on Ubuntu 20.04 and other Linux Ubuntu Systems. Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. It helps to run JavaScript anywhere anytime.
Node.js is a free, open-sourced, cross-platform JavaScript run-time environment that lets developers write command line tools and server-side scripts outside of a browser.
As Node.js provides support for the JavaScript programming language, Node.js has been adapted to work in a wide variety of places. Note that Node.js is open source and actively maintained by contributors all over the world.
Node.js – Technical Details
Node.js runs the V8 JavaScript engine, the core of Google Chrome, outside of the browser. This allows Node.js to be very performant. A Node.js app is run in a single process, without creating a new thread for every request. Node.js provides a set of asynchronous I/O primitives in its standard library that prevent JavaScript code from blocking and generally, libraries in Node.js are written using non-blocking paradigms, making blocking behavior the exception rather than the norm.
When Node.js performs an I/O operation, like reading from the network, accessing a database or the filesystem, instead of blocking the thread and wasting CPU cycles waiting, Node.js will resume the operations when the response comes back.
This allows Node.js to handle thousands of concurrent connections with a single server without introducing the burden of managing thread concurrency, which could be a significant source of bugs.
Node.js has a unique advantage because millions of frontend developers that write JavaScript for the browser are now able to write the server-side code in addition to the client-side code without the need to learn a completely different language.
Download Node.js
Download the Node.js source code or a pre-built installer for your platform. Latest LTS Version: 12.18.0 (includes npm 6.14.4) – https://nodejs.org/en/download/
Install Node.js
Debian and Ubuntu based Linux distributions, Enterprise Linux/Fedora and Snap packages
Node.js binary distributions are available from NodeSource.
Note: The packages on this page are maintained and supported by their respective packagers, not the Node.js core team.
Install Node.js via Terminal
You can also install Node.js via the following command:
Method 1:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nodejs
nodejs -v
Method 2:
sudo apt-get update
sudo apt-get upgrade
cd ~
curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
nano nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs
nodejs -v
Installing Node.js via package manager
Debian and Ubuntu based Linux distributions, Enterprise Linux/Fedora and Snap packages
nvm
is a popular way to run Node.js. It allows you to easily switch the Node.js version, and install new versions to try and easily rollback if something breaks, for example.
It is also very useful to test your code with old Node.js versions.
See https://github.com/creationix/nvm for more information about this option.