案例:centos7上二进制安装node18
起因:centos7无法直接安装node18,因为存在glibc版本兼容性问题。
使用社区兼容的二进制包(推荐)
这是最简单、最可靠的方法,由Node.js社区维护,专门为CentOS 7等旧系统重新编译,无需自己编译源码。
1、下载兼容版本(我直接用浏览器下载然后上传到服务器,并且正确上网方式下载更快)
从 unofficial-builds.nodejs.org 下载文件名中包含 glibc-217 的包,例如 node-v18.20.5-linux-x64-glibc-217.tar.gz。
# 示例:下载v18.20.5
cd /tmp
wget https://unofficial-builds.nodejs.org/download/release/v18.20.5/node-v18.20.5-linux-x64-glibc-217.tar.gz
2、解压并配置环境变量
cd software/
[hytest@ecs-e06e software]$ rz rz waiting to receive. Starting zmodem transfer. Press Ctrl+C to cancel. Transferring node-v18.20.5-linux-x64-glibc-217.tar.gz... 100% 43721 KB 3363 KB/sec 00:00:13 0 Errors [hytest@ecs-e06e software]$ tar -zxf node-v18.20.5-linux-x64-glibc-217.tar.gz [hytest@ecs-e06e software]$ ls jdk1.8.0_291 nginx nginx-1.22.0.tar.gz node-v18.20.5-linux-x64-glibc-217 node-v18.20.5-linux-x64-glibc-217.tar.gz [hytest@ecs-e06e software]$ mv node-v18.20.5-linux-x64-glibc-217 node18 [hytest@ecs-e06e software]$ node18/ bin/ include/ lib/ share/ [hytest@ecs-e06e software]$ node18/bin/node -v v18.20.5 [hytest@ecs-e06e software]$ pwd /home/hytest/software [hytest@ecs-e06e software]$ exit logout root@192.168.0.110[12:17:02]:/tmp $ echo 'export NODE_HOME=/home/hytest/software/node18' | sudo tee -a /etc/profile export NODE_HOME=/home/hytest/software/node18 root@192.168.0.110[12:17:05]:/tmp $ cat /etc/profile # /etc/profile # System wide environment and startup programs, for login setup # Functions and aliases go in /etc/bashrc # It's NOT a good idea to change this file unless you know what you # are doing. It's much better to create a custom.sh shell script in # /etc/profile.d/ to make custom changes to your environment, as this # will prevent the need for merging in future updates. pathmunge () { case ":${PATH}:" in *:"$1":*) ;; *) if [ "$2" = "after" ] ; then PATH=$PATH:$1 else PATH=$1:$PATH fi esac } if [ -x /usr/bin/id ]; then if [ -z "$EUID" ]; then # ksh workaround EUID=`/usr/bin/id -u` UID=`/usr/bin/id -ru` fi USER="`/usr/bin/id -un`" LOGNAME=$USER MAIL="/var/spool/mail/$USER" fi # Path manipulation if [ "$EUID" = "0" ]; then pathmunge /usr/sbin pathmunge /usr/local/sbin else pathmunge /usr/local/sbin after pathmunge /usr/sbin after fi HOSTNAME=`/usr/bin/hostname 2>/dev/null` HISTSIZE=1000 if [ "$HISTCONTROL" = "ignorespace" ] ; then export HISTCONTROL=ignoreboth else export HISTCONTROL=ignoredups fi export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL # By default, we want umask to get set. This sets it for login shell # Current threshold for system reserved uid/gids is 200 # You could check uidgid reservation validity in # /usr/share/doc/setup-*/uidgid file if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then umask 002 else umask 022 fi for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null fi fi done unset i unset -f pathmunge JAVA_HOME=/home/hytest/software/jdk1.8.0_291 JRE_HOME=$JAVA_HOME/jre PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export JAVA_HOME JRE_HOME PATH CLASSPATH export NODE_HOME=/home/hytest/software/node18 root@192.168.0.110[12:17:10]:/tmp $ echo 'export PATH=$NODE_HOME/bin:$PATH' | sudo tee -a /etc/profile export PATH=$NODE_HOME/bin:$PATH root@192.168.0.110[12:17:20]:/tmp $ source /etc/profile root@192.168.0.110[12:17:26]:/tmp $ su - hytest Last login: Wed Oct 28 12:14:07 CST 2026 on pts/0 [hytest@ecs-e06e ~]$ node -v v18.20.5 [hytest@ecs-e06e ~]$ npm -v 10.8.2
浙公网安备 33010602011771号