In this tutorial, we will show you how to install the automation platform called Node-RED on Ubuntu.
Node-RED is an incredibly powerful automation software that allows you to easily automate tasks by dragging and dropping nodes on a screen. We use this software a lot to help automate many things around our house, including monitoring our water tank levels.
If you use software like Home Assistant, you will probably be somewhat familiar with Node-RED and how easy it is to set up automations.
These steps for installing Node-RED will walk on any recent version of Ubuntu that you may be using. As long as your system can run Node.js, it should be able to run Node-RED.
While we use this software for home automation, it can also be used to do plenty of other tasks. You can even include your own JavaScript making you not restricted to specific nodes. There is also a wealth of libraries that expand the functionality of Node-RED.
Simple Steps to Installing Node-RED on Ubuntu
Over the following steps, we will walk you through the process of installing and running Node-RED on Ubuntu.
Preparing your System
1. Before proceeding any further we will need to install two pieces of software that we require to run Node-RED on Ubuntu. Those two pieces are Node.js and NPM. Node.js is the JavaScript runtime that runs Node-RED, and NPM is the package manager we will use to install Node-RED.
If you don’t have Node.js installed, we highly recommend following our tutorial on installing Node.js on Ubuntu. In particular, you will want to follow the second section.
https://pimylifeup.com/ubuntu-install-nodejs/
Installing Node-RED on Ubuntu using NPM
2. Thanks to us installing NPM in the previous step, installing Node-RED onto Ubuntu is now incredibly simple.
All you need to do to install Node-RED is to run the following command within the terminal. With this command, we use the “-g
” flag to install this software globally, and then the “--unsafe-perm
” option to install this tool under the root user.
sudo npm install -g --unsafe-perm node-red
Once Node-RED has been installed on your system, you should see some text, including the following. This text shows the number of packages that were added to run Node-RED.
added 312 packages in 22s
3. We can verify that Node-RED has been installed by using the following command within the terminal.
With this command, we are simply getting Node-RED to output its version.
node-red --version
Below is an example of what is output by this command. Here, you can see that we installed version 4.0.2, which is running off of Node.js 22.
Node-RED v4.0.2
Node.js v22.8.0
Linux 6.8.0-41-generic x64 LE
Starting Node-RED for the First Time
4. At the moment, we don’t have Node-RED installed to run as a service, so we will need to manually launch it
Before we set up the service, let us fire up Node-RED on Ubuntu for the first time so you can see how you can access the web interface.
Starting up Node-RED is as simple as using the following command.
node-red
Once you see the following text within the terminal, you know that Node-RED is up and running.
10 Sep 22:21:29 - [info] Server now running at http://127.0.0.1:1880/
10 Sep 22:21:29 - [info] Starting flows
10 Sep 22:21:29 - [info] Started flows
5. Next, you will want to open your favorite web browser and go to the following address. By default, Node-RED’s web interface operates on port 1880.
If you don’t know the IP address of your Ubuntu machine, then one of the easiest methods is to use the hostname command.
http://<IPADDRESS>:1880
6. If everything has worked correctly, you should now be greeted by the Node-RED web interface.
While you can begin to use this immediately, you will probably want to set the software to start up at boot.
Running Node-RED as a Service on Ubuntu
7. One key problem with how we currently have Node-RED set up on Ubuntu is that we must start it manually every time we want to use it.
Getting Node-RED to start on boot is simple, but it requires us to install and use pm2.
You can install PM2 on your Ubuntu system by running the following command within the terminal. PM2 is a process manager that makes keeping Node programs running relatively straightforward.
sudo npm install -g pm2
8. Once you have PM2 installed on Ubuntu, we can start the Node-RED runtime using the command below.
The process manager will now start and continue to manage Node-RED but won’t yet start it on boot.
pm2 start /usr/bin/node-red -- -v
You will know that this has all worked successfully as you will see a message similar to the one below appear within the terminal. Here, it tells you that Node-RED has been started on your Ubuntu system and provides its current status.
[PM2] Spawning PM2 daemon with pm2_home=/home/pimyubu/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting /usr/bin/node-red in fork_mode (1 instance)
[PM2] Done.
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ node-red │ fork │ 0 │ online │ 0% │ 28.7mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
9. To get the process manager to save that it is now managing Node-RED, you will want to use PM2’s save command by running the following command.
pm2 save
10. With the process manager saved, we want it to start at boot-up. By getting it to start at boot, Node-RED will also start when Ubuntu boots.
You should use the command below in the terminal to set this up.
pm2 startup systemd
This command won’t actually set everything up for you. Instead, it will generate a command that you will need to run.
[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pimyubu --hp /home/pimyubu
11. Your final step to setting up Node-RED on Ubuntu is to run the command that was generated by the previous step.
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pimyubu --hp /home/pimyubu
After running the previous command, you should see the following message once everything is successfully set up.
[PM2] [v] Command successfully executed.
Conclusion
Hopefully, at this point in the guide, you will have successfully installed and run Node-RED on your Ubuntu system.
Node-RED is a fantastic automation tool that makes automating tasks a breeze thanks to its easy-to-use web interface.
Please feel free to post a comment below if you have had any issues with getting Node-RED running.
If you found this tutorial to be helpful, we highly recommend that you check out our many other Ubuntu guides.