banner
venom

venom

Ubuntu安装Node.js

操作系统:Ubuntu 18.04.6 LTS
内核:Linux 4.15.0-169-generic
架构:x86-64

  • 安装 Node.js 18.x 后在 Ubuntu 18.04 上出现错误:
root@ubuntu:~# node -v
node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node)

这是因为 Ubuntu 18.04 默认的 glibc 版本为 2.27

root@ubuntu:~# ldd --version
版权所有 (C) 2018 Free Software Foundation, Inc.
  • 在这里卸载 Node.js 并重新安装
root@ubuntu:~# sudo apt remove nodejs
root@ubuntu:~# sudo apt remove npm
root@ubuntu:~# sudo apt autoremove

删除/usr/local/lib/usr/local/include/usr/local/bin下的所有nodenode_modules文件

  • 安装 Node.js 16.x
root@ubuntu:~# curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
root@ubuntu:~# sudo apt-get install -y nodejs
  • 验证
root@ubuntu:~# node -v
v16.18.1
root@ubuntu:~# npm -v
8.19.2
root@ubuntu:~# npx -v
8.19.2
  • 安装 yarn
root@ubuntu:~# curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
ok
root@ubuntu:~# echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
deb https://dl.yarnpkg.com/debian/ stable main
root@ubuntu:~# apt update
root@ubuntu:~# apt install yarn
  • 验证
root@ubuntu:~# yarn --version
1.22.19
  • 查看当前 yarn 镜像源
root@ubuntu:~# yarn config get registry
https://registry.yarnpkg.com
  • 切换到淘宝镜像源
root@ubuntu:~# yarn config set registry 'https://registry.npm.taobao.org'
yarn config v1.22.19
success Set "registry" to "https://registry.npm.taobao.org".
Done in 0.02s.
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。