ubuntu安装node.js 2023年最新

逃离我推掉我的手 2024-04-06 11:12 139阅读 0赞

安装说明

Node.js v18.x
可以直接粘贴 不用改成具体的版本

  1. # Using Ubuntu
  2. curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
  3. sudo apt-get install -y nodejs
  4. # Using Debian, as root
  5. curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
  6. apt-get install -y nodejs

Node.js v16.x

  1. # Using Ubuntu
  2. curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
  3. sudo apt-get install -y nodejs
  4. # Using Debian, as root
  5. curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
  6. apt-get install -y nodejs

Node.js v14.x

  1. # Using Ubuntu
  2. curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
  3. sudo apt-get install -y nodejs
  4. # Using Debian, as root
  5. curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
  6. apt-get install -y nodejs

Node.js LTS (v16.x)

  1. # Using Ubuntu
  2. curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
  3. sudo apt-get install -y nodejs
  4. # Using Debian, as root
  5. curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
  6. apt-get install -y nodejs

Node.js当前 (v18.x):

  1. # Using Ubuntu
  2. curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
  3. sudo apt-get install -y nodejs
  4. # Using Debian, as root
  5. curl -fsSL https://deb.nodesource.com/setup_current.x | bash -
  6. apt-get install -y nodejs

可选:安装构建工具

要从 npm 编译和安装本机插件,您可能还需要安装构建工具:

  1. # use `sudo` on Ubuntu or run this as root on debian
  2. apt-get install -y build-essential

卸载ubuntu和debian安软件包nodejs

要完全删除 Node.js请从上面的 deb.nodesource.com 包方法中安装:

  1. # use `sudo` on Ubuntu or run this as root on debian
  2. apt-get purge nodejs
  3. rm -r /etc/apt/sources.list.d/nodesource.list

手动安装

如果您不是 的粉丝,或者正在使用不受支持的发行版,则可以尝试手动安装。curl <url> | bash -

这些指令假定存在,但是某些分发版默认情况下不包含此命令,特别是那些专注于最小环境的分发。在这种情况下,您应该安装 或 到 root 以直接运行命令。sudo``sudo``su

1. 删除旧的 PPA(如果存在)

仅当您之前使用过 Chris Lea 的节点.js PPA 时,才需要执行此步骤。

  1. # add-apt-repository may not be present on some Ubuntu releases:
  2. # sudo apt-get install python-software-properties
  3. sudo add-apt-repository -y -r ppa:chris-lea/node.js
  4. sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list
  5. sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list.save

2. 添加节点源包签名密钥

  1. KEYRING=/usr/share/keyrings/nodesource.gpg
  2. curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
  3. # wget can also be used:
  4. # wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
  5. gpg --no-default-keyring --keyring "$KEYRING" --list-keys

密钥 ID 为 。9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280

3. 添加所需的节点源存储库

  1. # Replace with the branch of Node.js or io.js you want to install: node_6.x, node_8.x, etc...
  2. VERSION=node_8.x
  3. # Replace with the keyring above, if different
  4. KEYRING=/usr/share/keyrings/nodesource.gpg
  5. # The below command will set this correctly, but if lsb_release isn't available, you can set it manually:
  6. # - For Debian distributions: jessie, sid, etc...
  7. # - For Ubuntu distributions: xenial, bionic, etc...
  8. # - For Debian or Ubuntu derived distributions your best option is to use the codename corresponding to the upstream release your distribution is based off. This is an advanced scenario and unsupported if your distribution is not listed as supported per earlier in this README.
  9. DISTRO="$(lsb_release -s -c)"
  10. echo "deb [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
  11. echo "deb-src [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list

4. 更新软件包列表并安装 Node.js

  1. sudo apt-get update
  2. sudo apt-get install nodejs

发表评论

表情:
评论列表 (有 0 条评论,139人围观)

还没有评论,来说两句吧...

相关阅读

    相关 ubuntu安装nodejs

    推荐使用方法1进行安装 在nodejs官方网站download页面中选择需要使用的版本,可以选择LTS或current,选择对应系统右键复制链接地址 ![这里写图片