Node-RED是基于 Node.js 开发的开源产品,它需要先安装NodeJS,然后再其中安装Node-RED组件。
Linux操作系统
推荐Ubuntu Server 22.04 LTS版本,或者Ubuntu Server 24.04 LTS版本,
1、Node.js:16.x以上版本
请到Ubuntu的页面下载服务器版本
# x86工控机的ubuntu-22服务器版
https://releases.ubuntu.com/jammy/ubuntu-22.04.3-live-server-amd64.iso
下列流程参考了:《Ubuntu上Node.js的完全卸载与最新版安装》
# 更新源
apt-get update -y
#安装curl
apt install git curl -y
#下载指定的nodejs的18版
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
# 本地安装NodeJs
apt-get install -y nodejs
#检查是否安装成功
node -v
npm -v
npx -v
# 切换为国内的安装源(比如华为源),主要是国外的太慢了,容易因为超时而安装不成功
npm config set registry https://mirrors.huaweicloud.com/repository/npm
# 安装nodered,安装时间比较长,需要等待一会
npm install -g --unsafe-perm node-red
# node-red启动
node-red
#可以访问Node-RED的前端页面,端口号是1880,例如
#http://192.168.1.23:1880/
#卸载node-red
npm uninstall -g node-red
#查找残留配置:默认安装时候,本地会残留/root/.node-red
find / -name 'node-red'
#删除本地残留文件
rm -rf /root/.node-red
#卸载nodejs
apt remove nodejs
#卸载npm
apt remove npm
pm2是node.js应用的开机启动工具,安装它后,可以将Node-RED托管给pm2进行开机启动
#安装pm2
npm install pm2 -g
#查看安装是否成功
pm2 status
#使用pm2启动node-red
pm2 start node-red
#保存已添加的node-red例程
pm2 save
pm2 startup
#重启pm2
pm2 restart node-red
#查看托管的node.js应用
pm2 status