Ubuntu安装最新nodejs

环境:Ubuntu 20.04.6

问题描述

由于ubuntu默认的apt下载器只能下载较老版本的nodejs,而使用源代码编译又有点麻烦,因此这里采用github上官方推荐的方式,推荐看官方的教程,里面还介绍了nodejs和ubuntu的对应版本,地址如下:https://github.com/nodesource/distributions。

安装步骤

  1. Download and import the Nodesource GPG key:

    sudo apt update
    sudo apt install -y ca-certificates curl gnupg
    sudo mkdir -p /etc/apt/keyrings
    curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
    
  2. Create deb repository:

    NODE_MAJOR=20
    echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
    

    注意:这里的NODE_MAJOR就是你想安装的nodejs版本,可以根据需要自行修改。

  3. Run Update and Install:

    sudo apt-get update
    sudo apt-get install nodejs -y
    
  4. 安装完毕。

卸载步骤

apt purge nodejs &&\
rm -r /etc/apt/sources.list.d/nodesource.list &&\
rm -r /etc/apt/keyrings/nodesource.gpg

其中的&&\意思是:左边的命令如果执行成功,那么就执行右边的命令。

posted @   BinaryPrinter  阅读(35)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示