一、使用 NVM 安装 Node.js
1.安装nvm
# $ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
2.测试是否安装完成# command -v nvm
3.列出 Node.JS 的所有可用版本
#nvm ls-remote
4.列出 Node.JS 版本的所有最新 LTS 版本
#nvm ls-remote | grep -i latest
5.安装node默认最新版本
#nvm install node
6.安装指定版本# nvm install 18.19.1
7.
切换到该版本
# nvm use <version>
8.设置版本成为默认版本
# nvm alias default <version>
二、安装node安装包
1.下载安装包 # wget https://npm.taobao.org/mirrors/node/v14.19.3/node-v14.19.3-linux-x64.tar.gz 2.解压 # tar -zxvf node-v14.19.3-linux-x64.tar.gz 3.进图bin目录 # cd /***..../node-v14.19.3-linux-x64/bin 4.创建软连接 # ln -s /usr/local/node/node-v14.19.3-linux-x64/bin/npm /usr/local/bin/npm # ln -s /usr/local/node/node-v14.19.3-linux-x64/bin/node /usr/local/bin/node 5.配置环境变量 # vim /etc/profile (放入文件末尾) NODE_HOME=/usr/local/node/node-v14.17.0-linux-x64 PATH=$NODE_HOME/bin:$PATH export NODE_HOME PATH 6.生效配置 # source /etc/profile
三、报错问题
测试:npm -v & node -v #npm -v node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node) node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by node) node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node) node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node) node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by nod node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by nod -------------------------------------------------------------------------------------------- 解决: 1.查看系统内安装的glibc版本 # strings /lib64/libc.so.6 |grep GLIBC_ 2.安装glibc # wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz # tar xf glibc-2.28.tar.gz # cd glibc-2.28/ && mkdir build && cd build # ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin --------------------------------> # 这一步提示如下错误 # configure: error: # *** These critical programs are missing or too old: compiler # *** Check the INSTALL file for required versions. 1.升级 gcc-8 1> 安装scl源; # yum install -y centos-release-scl scl-utils-build 2>列出scl可用源下所有可用版本 # yum list all --enablerepo='centos-sclo-rh' | grep "devtoolset-" 3>安装指定版本的gcc # yum install -y devtoolset-8-toolchain 4>使用指定版本的gcc(只对当前bash有效) # scl enable devtoolset-8 bash 2.升级 make 1>下载解压 # wget https://ftp.gnu.org/gnu/make/make-4.3.tar.gz # tar -xf make-4.3.tar.gz && cd make-4.3/ 2>安装到指定目录 # ./configure --prefix=/usr/local/make # make && make install 3>创建软连接 # cd /usr/bin/ && mv make make.bak # ln -sv /usr/local/make/bin/make /usr/bin/make 3.重新编译glibc # cd /****..../glibc-2.28/build # ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin 4.更新动态库 1>安装 # yum install libstdc++.so.6 -y 2>查看动态库 # strings /usr/lib/libstdc++.so.6 | grep 'CXXABI' 3>下载需要的版本,并且软连接至系统 # wget http://ftp.de.debian.org/debian/pool/main/g/gcc-8/libstdc++6_8.3.0-6_amd64.deb # ar -x libstdc++6_8.3.0-6_amd64.deb # tar -xvf data.tar.xz 4>删除低版本库的软连接并软连接至系统 # cp usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25 /usr/lib64/ # rm -rf /usr/lib64/libstdc++.so.6 # ln -s /usr/lib64/libstdc++.so.6.0.25 /usr/lib64/libstdc++.so.6
四、测试
]# node -v v18.19.1 ]# npm -v 10.2.4
标签:node,bin,nodejs,--,make,环境,usr,so.6,安装 From: https://www.cnblogs.com/Zhangtao-linux/p/18080193