How to install Node.js in Ubuntu 18.04

Prologue

Node.js is an open-source, cross-platform runtime environment that executes JavaScript code outside of a browser. Node.js lets developers use JavaScript to write command line tools and for server-side scripting—running scripts server-side to produce content before the page is sent to the user’s web browser. Consequently, Node.js represents a “JavaScript everywhere” paradigm, unifying web application development around a single programming language, rather than different languages for server- and client-side scripts.

Though .js is the standard filename extension for JavaScript code, the name “Node.js” does not refer to a particular file in this context and is merely the name of the product. Node.js has an event-driven architecture capable of asynchronous I/O. These design choices aim to optimize throughput and scalability in web applications with many input/output operations, as well as for real-time Web applications (e.g., real-time communication programs and browser games.


In this guide, we will explore a quite known method of installing Node.js: through the NodeSource repository

Pre-requisites and assumptions

  • This guide is designed to fit Ubuntu 18.04 systems, but can apply to Debian 9, although I won’t provide support for Debian.
  • You should have also setup a sudo user. Installing stuff as root is possible, but highly discouraged

But why should I install it with a PPA?

The reason is simple: It is installed system-wide. This means, you don’t have to install a (quite dodgy) script every time on every new user that needs node.js.

So let me begin with…

Step 1: Updating your system packages

This should be fairly easy for a great sysadmin like you winkwink. Just run

sudo apt update
sudo apt upgrade

When that is finally finished, you should advance to …

Step 2: Adding the repository

First, make sure GPG is installed by running

# install the gnupg package
sudo apt install gnupg

and then add the repo by using

# This is a script provided by NodeSource. Replace VERSION with the version you want to get
curl -sL https://deb.nodesource.com/setup_VERSION.x | sudo -E bash -

Step 3: Installing node.js

sudo apt install nodejs

And… that’s it! :tada:

EXTRA: Install the C++ build tools

Some popular packages like bcrypt and bufferutil are written in C++ and need python 2.7 and the C++ build tools to well… be built.
Luckily, it’s quite easy to install them! Just run

# Installs the build-essentials package group
sudo apt install build-essential
1 Like

theres a much simpler solution, but ok :confused:

>:( why don’t you read the goddamn thing

1: not dodgy
2: if you follow instructions, you can make any node version available for ALL users

There is more than one way to install Node.js, I recommend you modify the title to show that this is the Nodesource Script instead of installing directly from Node themselves.