Node-RED: installation and configuration on Ubuntu 16.04 LTS

In previous tutorials we have seen how to install Node-RED on Windows, MacOS and Raspbian (Raspberry PI). In this tutorial we will install Node-RED on Ubuntu 16.04 LTS (Long Term Support) on an Atom-based mini PC. We will install Node.js, npm (the package manager of Node.js) and Node-RED.

Install Node.js and npm

Installing Node.js is very simple on Ubuntu 16.04 LTS because it is included in the default repositories. In a Terminal, run the following command:

This command installs Node.js version v4.2.x LTS which means that this version will be maintained for another 30 months from the release date, ie October 12, 2015.

After installation, check the installed version.

Node.js uses a package manager called npm (Node Package Manager). It allows you to install and manage packages. Since Node-RED is a “over-layer graphics” of Node.js, it is necessary to install it.

When the installation is complete, check the version. If the version is returned without error, you can continue the installation of Node-RED.

Install Node-RED on Ubuntu (16.04 LTS +)

Node-RED installs using the npm package manager. We will take advantage of this to install the node-red-admin module which adds some administration tools for Node-RED.

By default, npm installs the packages in the current directory. The -g option installs packages globally, meaning that they will be available for all Node.js. In this case, they are installed in the / usr / local / bin directory. The –unsafe-perm option overrides any errors that may occur during installation. For example, when certain modules are to be compiled at the time of installation.

Node-RED uses port 1880 by default. It must therefore be authorized.

And now, you can start Node-RED with the command node-red .

To access it, open a web browser and enter the following URL in the address bar http://localhost:1880

node-red ubuntu 16.04 lts

Run Node-RED automatically at startup

To be able to start Node-RED automatically when Ubuntu starts, we will create a script that will be launched by systemd.

Open an empty file named node-red.service

Paste the contents of this script and then replace the USER key with your username. Save the file with CTRL+X and then Y.

Some explanations on the configuration:

  • The first section (Unit) indicates that the service should start after the network and the syslog service are up and running.
  • The [service] section. ExecStart indicates the program started and the resources allocated for its operation.
  • Restart = on-failure to restart Node-RED in case of crash
  • The events will be identified in the system log (StandardOutput = syslog) with the node-red identifier.

Now that the configuration file is ready, we tell systemd to run it at startup.

Let’s start it manually (Do not forget to stop Node-RED if another instance is already running).

Now that Node-RED works as a service, you have to go through systemd to stop it manually.

Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.

DIY Projects