文章

linux ubuntu安装最新的nodejs版本

服务器ubuntu22.04上安装nodejs稳定版本

1.执行安装脚本

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - 

sudo apt-get install -y nodejs

其中setup_lts.x 可以改成你想要安装的版本

比如18.x的最新的版本就执行

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -

其他安装具体可查看

https://github.com/nodesource/distributions

2.如需安装多个版本,可使用node管理工具nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

#安装稳定的最新版本
nvm install --lts


#安装18.x最新版本
nvm install 18

具体可看:

https://github.com/nvm-sh/nvm

许可协议:  CC BY 4.0