{"id":373,"date":"2025-11-14T11:06:17","date_gmt":"2025-11-14T03:06:17","guid":{"rendered":"https:\/\/zhaoyanqi.cn\/?p=373"},"modified":"2025-11-14T17:16:20","modified_gmt":"2025-11-14T09:16:20","slug":"centos-7-%e5%ae%89%e8%a3%85-node-js-18-%e6%95%99%e7%a8%8b%ef%bc%88%e5%90%ab-glibc-2-28-gcc8-%e6%94%af%e6%8c%81%ef%bc%89","status":"publish","type":"post","link":"https:\/\/zhaoyanqi.cn\/?p=373","title":{"rendered":"CentOS 7.9 \u5b89\u88c5 Node.js 18"},"content":{"rendered":"\n<p>\u9002\u7528\u7cfb\u7edf\uff1aCentOS 7 \/ RHEL 7 \/ TencentOS Server 2.x \u9002\u7528\u573a\u666f\uff1a\u7cfb\u7edf glibc \u7248\u672c\u4f4e\uff082.17\uff09\uff0c\u76f4\u63a5\u5b89\u88c5 Node18 \u62a5\u9519\u65f6\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u95ee\u9898\u80cc\u666f<\/h2>\n\n\n\n<p>CentOS 7 \u9ed8\u8ba4\u4f7f\u7528 <strong>glibc 2.17<\/strong>\uff0c\u800c Node.js 18 \u53ca\u4ee5\u4e0a\u7248\u672c\u9700\u8981\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>GLIBC_2.25<\/code> \/ <code>GLIBC_2.27<\/code> \/ <code>GLIBC_2.28<\/code><\/li>\n\n\n\n<li><code>GLIBCXX_3.4.20<\/code> \/ <code>GLIBCXX_3.4.21<\/code> \/ <code>CXXABI_1.3.9<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u5982\u679c\u76f4\u63a5\u5b89\u88c5 Node18\uff0c\u4f1a\u51fa\u73b0\u5982\u4e0b\u9519\u8bef\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">node: \/lib64\/libm.so.6: version `GLIBC_2.27' not found<br>node: \/lib64\/libstdc++.so.6: version `GLIBCXX_3.4.21' not found<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u5b89\u88c5\u5fc5\u8981\u5de5\u5177<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u914d\u7f6e\u963f\u91cc\u4e91 Yum \u6e90<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo cat \/etc\/yum.repos.d\/CentOS-Base.repo &lt;&lt;'EOF'\n&#91;base]\nname=CentOS-7 - Base - aliyun\nbaseurl=http:\/\/mirrors.aliyun.com\/centos\/7\/os\/x86_64\/\ngpgcheck=1\ngpgkey=http:\/\/mirrors.aliyun.com\/centos\/RPM-GPG-KEY-CentOS-7\n\n&#91;updates]\nname=CentOS-7 - Updates - aliyun\nbaseurl=http:\/\/mirrors.aliyun.com\/centos\/7\/updates\/x86_64\/\ngpgcheck=1\ngpgkey=http:\/\/mirrors.aliyun.com\/centos\/RPM-GPG-KEY-CentOS-7\n\n&#91;extras]\nname=CentOS-7 - Extras - aliyun\nbaseurl=http:\/\/mirrors.aliyun.com\/centos\/7\/extras\/x86_64\/\ngpgcheck=1\ngpgkey=http:\/\/mirrors.aliyun.com\/centos\/RPM-GPG-KEY-CentOS-7\nEOF\nyum makecache\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b89\u88c5\u5f00\u53d1\u5de5\u5177<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>yum install -y wget curl git gcc gcc-c++ make python3 openssl-devel zlib-devel\n\n# \u5b89\u88c5\u65b0\u7248make\n# 1) \u5b89\u88c5\u7f16\u8bd1\u4f9d\u8d56\nsudo yum groupinstall -y \"Development Tools\"\nsudo yum install -y wget tar\n\n# 2) \u4e0b\u8f7d\u5e76\u7f16\u8bd1 make\uff08\u793a\u4f8b\u7528 4.4.1\uff09\ncd \/tmp\nwget https:\/\/ftp.gnu.org\/gnu\/make\/make-4.4.1.tar.gz\ntar xf make-4.4.1.tar.gz\ncd make-4.4.1\n\n# 3) \u5b89\u88c5\u5230 \/opt\/make-4.4\uff0c\u4e0d\u8986\u76d6\u7cfb\u7edf\u7684 \/usr\/bin\/make\n.\/configure --prefix=\/opt\/make-4.4\nmake -j\"$(nproc)\"\nsudo make install\n\n# 4) \u8ba9\u65b0 make \u4f18\u5148\u751f\u6548\uff08\u5f53\u524d\u4f1a\u8bdd\uff09\nexport PATH=\/opt\/make-4.4\/bin:$PATH\nhash -r\nmake --version     # \u5e94\u663e\u793a 4.4.1\uff08\u6216\u4f60\u5b89\u88c5\u7684\u7248\u672c\uff09\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u5b89\u88c5 GCC 8\uff08\u901a\u8fc7 devtoolset-8\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>yum install -y centos-release-scl<br>yum install -y devtoolset-8 devtoolset-8-toolchain devtoolset-8-libstdc++-devel<br>scl enable devtoolset-8 bash<br>gcc --version<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u7f16\u8bd1\u5e76\u5b89\u88c5 glibc 2.28\uff08\u4e0d\u8986\u76d6\u7cfb\u7edf\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/usr\/local\/src\nwget https:\/\/ftp.gnu.org\/gnu\/libc\/glibc-2.28.tar.gz\ntar -xzf glibc-2.28.tar.gz\n\n# 2) \u8bbe\u5b9a\u6e90\u7801\u4e0e\u6784\u5efa\u76ee\u5f55\u53d8\u91cf\nSRC=\/usr\/local\/src\/glibc-2.28\nBUILD=\/usr\/local\/src\/glibc-2.28-build\n\n# 3) \u65b0\u5efa\u5e72\u51c0\u7684\u6784\u5efa\u76ee\u5f55\nrm -rf \"$BUILD\" &amp;&amp; mkdir -p \"$BUILD\"\ncd \"$BUILD\"\n\n# 4) \u786e\u4fdd\u7528\u65b0 make\nexport PATH=\/opt\/make-4.4\/bin:$PATH\nhash -r\n\n# 5) \u8fd0\u884c configure\uff08\u6307\u5411 *\u6b63\u786e\u7684* \u6e90\u7801\u8def\u5f84\uff09\nMAKE=\/opt\/make-4.4\/bin\/make \\\nGNUMAKE=\/opt\/make-4.4\/bin\/make \\\n\"$SRC\"\/configure \\\n  --prefix=\/opt\/glibc-2.28 \\\n  --enable-obsolete-nsl \\\n  --disable-werror \\\n  --cache-file=\/dev\/null\n\n# 6) \u7f16\u8bd1\u4e0e\u5b89\u88c5\uff08\u5e76\u884c\u5ea6\u53ef\u6309\u673a\u5668\u8c03\u4f4e\uff0c\u6bd4\u5982 -j2\uff09\nmake -j\"$(nproc)\"\nsudo make install<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p \/opt\/glibc-2.28\/etc<br>echo -e \"\/opt\/glibc-2.28\/lib\\n\/opt\/rh\/devtoolset-8\/root\/usr\/lib64\" &gt; \/opt\/glibc-2.28\/etc\/ld.so.conf<br>\/opt\/glibc-2.28\/sbin\/ldconfig -r \/opt\/glibc-2.28<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u5b89\u88c5 Node.js 18\uff08\u4f7f\u7528 nvm\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -o- https:\/\/raw.githubusercontent.com\/nvm-sh\/nvm\/v0.39.7\/install.sh | bash<br>source ~\/.bashrc<br>nvm install 18.19.1<br>nvm alias default 18.19.1<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u521b\u5efa\u517c\u5bb9 Node18 \u7684\u201c\u5305\u88c5\u5668\u201d<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>mv ~\/.nvm\/versions\/node\/v18.19.1\/bin\/node ~\/.nvm\/versions\/node\/v18.19.1\/bin\/node.real<br>cat &gt; ~\/.nvm\/versions\/node\/v18.19.1\/bin\/node &lt;&lt;'EOF'<br>#!\/usr\/bin\/env bash<br>NODE_REAL=\"\/root\/.nvm\/versions\/node\/v18.19.1\/bin\/node.real\"<br>GLIBC=\"\/opt\/glibc-2.28\"<br>LIBS=\"\/opt\/gcc8\/lib64:\/opt\/glibc-2.28\/lib:\/lib64:\/usr\/lib64\"<br>exec \"$GLIBC\/lib\/ld-linux-x86-64.so.2\" --library-path \"$LIBS\" \"$NODE_REAL\" \"$@\"<br>EOF<br>chmod +x ~\/.nvm\/versions\/node\/v18.19.1\/bin\/node<\/code><\/pre>\n\n\n\n<p>\u9a8c\u8bc1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node -v<br>npm -v<br>npx -v<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e03\u3001\u53ef\u9009\uff1a\u7cfb\u7edf\u7ea7 npm \u5305\u88c5\u5668<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tee \/usr\/local\/bin\/npm &gt;\/dev\/null &lt;&lt;'EOF'<br>#!\/usr\/bin\/env bash<br>NODE_HOME=\"\/root\/.nvm\/versions\/node\/v18.19.1\"<br>GLIBC=\"\/opt\/glibc-2.28\"<br>LIBPATH=\"$GLIBC\/lib:\/opt\/gcc8\/lib64:\/lib64:\/usr\/lib64\"<br>exec \"$GLIBC\/lib\/ld-linux-x86-64.so.2\" &nbsp; --library-path \"$LIBPATH\" &nbsp; \"$NODE_HOME\/bin\/node\" \"$NODE_HOME\/lib\/node_modules\/npm\/bin\/npm-cli.js\" \"$@\"<br>EOF<br>chmod +x \/usr\/local\/bin\/npm<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u516b\u3001\u6c38\u4e45\u751f\u6548<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>echo 'export PATH=\"\/usr\/local\/bin:\/opt\/node18-shim\/bin:$PATH\"' &gt;&gt; ~\/.bashrc<br>source ~\/.bashrc<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e5d\u3001\u81ea\u68c0<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/opt\/glibc-2.28\/lib\/ld-linux-x86-64.so.2 --list \"$(which node)\" | egrep 'libc|libstdc'<\/code><\/pre>\n\n\n\n<p>\u8f93\u51fa\u5e94\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>libc.so.6 =&gt; \/opt\/glibc-2.28\/lib\/libc.so.6<br>libstdc++.so.6 =&gt; \/opt\/gcc8\/lib64\/libstdc++.so.6<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5341\u3001\u5907\u4efd\u5f53\u524d\u53ef\u7528\u72b6\u6001<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>tar czf \/root\/node18-working-backup.tgz &nbsp; \/opt\/glibc-2.28 \/opt\/gcc8 &nbsp; ~\/.nvm\/versions\/node\/v18.19.1\/bin\/node &nbsp; ~\/.nvm\/versions\/node\/v18.19.1\/bin\/node.real<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u6700\u7ec8\u9a8c\u8bc1<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>node -v<br>npm -v<br>npm run build<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u66f4\u65b0\u5305\u88c5\u5668\u811a\u672c<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/env bash<br>VER=${1:-v18.19.1}<br>NODE_HOME=\"$HOME\/.nvm\/versions\/node\/$VER\"<br>mv \"$NODE_HOME\/bin\/node\" \"$NODE_HOME\/bin\/node.real\"<br>cat &gt;\"$NODE_HOME\/bin\/node\" &lt;&lt;EOF<br>#!\/usr\/bin\/env bash<br>NODE_REAL=\"$NODE_HOME\/bin\/node.real\"<br>GLIBC=\"\/opt\/glibc-2.28\"<br>LIBS=\"\/opt\/gcc8\/lib64:\/opt\/glibc-2.28\/lib:\/lib64:\/usr\/lib64\"<br>exec \"\\$GLIBC\/lib\/ld-linux-x86-64.so.2\" --library-path \"\\$LIBS\" \"\\$NODE_REAL\" \"\\$@\"<br>EOF<br>chmod +x \"$NODE_HOME\/bin\/node\"<br>echo \"Node $VER wrapper rebuilt successfully!\"<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9002\u7528\u7cfb\u7edf\uff1aCentOS 7 \/ RHEL 7 \/ TencentOS Server 2.x \u9002\u7528\u573a\u666f\uff1a\u7cfb\u7edf g [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-373","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/posts\/373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=373"}],"version-history":[{"count":7,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/posts\/373\/revisions"}],"predecessor-version":[{"id":384,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/posts\/373\/revisions\/384"}],"wp:attachment":[{"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}