NodeJS install on Ubuntu 16.04 LTS (Xenial Xerus)
Node.js is an open-source, cross-platform JavaScript runtime environment for developing a diverse variety of tools and applications. Although Node.js is not a JavaScript framework, many of its basic modules are written in JavaScript, and developers can write new modules in JavaScript. The runtime environment interprets JavaScript using Google’s V8 JavaScript engine.
— Wikipedia
For this installation and future NodeJS upgrades we will use npm.
npm consists of a command line client that interacts with a remote registry. It allows users to consume and distribute JavaScript modules that are available on the registry. Packages on the registry are in CommonJS format and include a metadata file in JSON format. Over 280,000 packages are available on the main npm registry.
— Wikipedia
If this is a fresh Ubuntu install,
go ahead and enable and secure your OpenSSH server on Ubuntu 16.04 LTS
Login to your server and pull the latest versions of the available packages:
sudo apt update
If you wish to upgrade all packages (recommended for fresh installs) also run:
sudo apt upgrade
Ok, so now we can begin the actual installation for our NodeJS Environment:
sudo apt install npm
sudo npm cache clean -f
sudo npm install -g n
If there are no errors you can proceed to upgrading NodeJS to the latest version:
sudo n stable
OR install a specific version like so:
sudo n 4.4.6
Finally you must create a symlink for NodeJS:
ln -sf /usr/local/n/versions/node/
Now you should have both NodeJS and npm installed and ready to use. You can check your installed versions using:
node -v
npm -v
Footnote:
If you want your NodeJS apps to be able to listen on port 80, then you should execute:
apt install libcap2-bin
After the installation is done, run:
sudo setcap cap_net_bind_service=+ep `readlink -f `which node``