Ubuntu下升级node.js从12.22到22.14
因为安装puter需要将node.js升级到22以上,而ubuntu22.04带的默认版本是12.22,因此操作升级到最新的22.14
两种方法,源代码编译安装和二进制安装。
从头源安装
# Download and install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
# in lieu of restarting the shell
\. "$HOME/.nvm/nvm.sh"
# Download and install Node.js:
nvm install 22
# Verify the Node.js version:
node -v # Should print "v22.14.0".
nvm current # Should print "v22.14.0".
# Verify npm version:
npm -v # Should print "10.9.2".
整个编译过程需要半小时 。
二进制安装
从官网下载安装包:Node.js — Download Node.js®
解压,
tar -xvf node-v22.14.0-linux-x64.tar.xz
比如解压到/home/xx/node-v22.14.0-linux-x64目录, 设定路径:
node -v
v12.22.9
export PATH=/home/xx/node-v22.14.0-linux-x64/bin:$PATH
node -v
v22.14.0
安装完成,整个过程只需要1分钟。