执行下面命令,安装nodejs 和 npm
ubuntu@ubuntu22:~$ sudo apt update
ubuntu@ubuntu22:~$ sudo apt install npm # npm 是 Node.js 的包管理工具
ubuntu@ubuntu22:~$ sudo apt install -y curl
ubuntu@ubuntu22:~$ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
ubuntu@ubuntu22:~$ sudo apt install -y nodejs
遇到如下报错
ubuntu@ubuntu22:~$ sudo apt-get install nodejs -y Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: libc-ares2 libnode72 Use 'sudo apt autoremove' to remove them. The following NEW packages will be installed: nodejs 0 upgraded, 1 newly installed, 0 to remove and 23 not upgraded. Need to get 0 B/29.6 MB of archives. After this operation, 187 MB of additional disk space will be used. Selecting previously unselected package nodejs. (Reading database ... 192008 files and directories currently installed.) Preparing to unpack .../nodejs_18.20.4-1nodesource1_amd64.deb ... Unpacking nodejs (18.20.4-1nodesource1) ... dpkg: error processing archive /var/cache/apt/archives/nodejs_18.20.4-1nodesource1_amd64.deb (--unpack): trying to overwrite '/usr/share/systemtap/tapset/node.stp', which is also in package libnode72:amd64 12.22.9~dfsg-1ubuntu3.6 Errors were encountered while processing: /var/cache/apt/archives/nodejs_18.20.4-1nodesource1_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)
这个错误表明在安装 Node.js 18 时,出现了文件冲突问题,特别是 node.stp
文件被两个不同的包(nodejs
和 libnode72
)包含。解决这个问题的办法通常是先卸载冲突的旧版本,再安装新的 Node.js 版本
解决步骤:
ubuntu@ubuntu22:~$ sudo apt-get remove libnode72
ubuntu@ubuntu22:~$ sudo apt autoremove
ubuntu@ubuntu22:~$ sudo apt install -y nodejs
脚本内容如下:
ubuntu@ubuntu22:~$ cat update_html.js
const juice = require('juice'); const fs = require('fs'); const html = fs.readFileSync('file.html', 'utf8'); const inlinedHtml = juice(html); console.log(inlinedHtml);
执行脚本获得新的html文件:
ubuntu@ubuntu22:~$ nodejs update_html.js > new.html
标签:sudo,nodejs,ubuntu,apt,html,格式,ubuntu22,CSS From: https://www.cnblogs.com/yaolaoer/p/18534910