【笔记】Nodejs安装笔记

前言

Nodejs安装笔记

MacOS

1
brew install nodejs

Linux

Debian

1
2
apt install nodejs
apt install npm

踩坑

  • npm与nodejs的版本不对应
解决问题
  • 不安装nodejs直接安装npm,将nodejs作为npm的依赖安装
1
apt install npm

踩坑

  • apt仓库中的nodejs版本过低
解决问题
  • 升级nodejs源
  • 这种方式无需直接安装npm来得到版本对应的nodejs,而是在安装nodejs时会直接安装版本对应的npm
1
2
curl -fsSL https://deb.nodesource.com/setup_current.x | bash -
apt install nodejs

CentOS

1
2
curl --silent --location https://rpm.nodesource.com/setup_18.x | bash -
yum install nodejs

踩坑

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
                            DEPRECATION WARNING                            

Node.js 7.x is no longer actively supported!

You will not receive security or critical stability updates for this version.

You should migrate to a supported version of Node.js as soon as possible.
Use the installation script that corresponds to the version of Node.js you
wish to install. e.g.

* https://rpm.nodesource.com/setup_16.x - Node.js v16 "Gallium"
* https://rpm.nodesource.com/setup_18.x - Node.js v18 LTS "Hydrogen" (recommended)
* https://rpm.nodesource.com/setup_19.x — Node.js v19 "Nineteen"
* https://rpm.nodesource.com/setup_20.x — Node.js v20 "Iron" (current)

Please see https://github.com/nodejs/Release for details about which
version may be appropriate for you.

The NodeSource Node.js distributions repository contains
information both about supported versions of Node.js and supported Linux
distributions. To learn more about usage, see the repository:
https://github.com/nodesource/distributions
解决问题
  • 安装受支持的版本https://rpm.nodesource.com/setup_18.x

踩坑

1
2
3
node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by node)
解决问题
更新libstdc++.so.6.0.26
1
2
3
wget https://cdn.frostbelt.cn/software/libstdc%2B%2B.so.6.0.26
mv libstdc++.so.6.0.26 /usr/lib64/
ln -snf /usr/lib64/libstdc++.so.6.0.26 /usr/lib64/libstdc++.so.6
更新glibc
1
2
3
4
5
6
7
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
make && make install

完成

参考文献

博客园——皮豪
CSDN——重塑10年
CSDN——IT云清
博客园——六月OvO