当前位置: 首页 > 工具软件 > Deb.js > 使用案例 >

ubuntu安装node.js 2023年最新

顾兴昌
2023-12-01

安装说明

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

# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt-get install -y nodejs

Node.js v16.x

# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
apt-get install -y nodejs

Node.js v14.x

# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
apt-get install -y nodejs

Node.js LTS (v16.x)

# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs

Node.js当前 (v18.x):

# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -fsSL https://deb.nodesource.com/setup_current.x | bash -
apt-get install -y nodejs

可选:安装构建工具

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

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

卸载ubuntu和debian安软件包nodejs

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

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

手动安装

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

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

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

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

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

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

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

密钥 ID 为 。9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280

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

# Replace with the branch of Node.js or io.js you want to install: node_6.x, node_8.x, etc...
VERSION=node_8.x
# Replace with the keyring above, if different
KEYRING=/usr/share/keyrings/nodesource.gpg
# The below command will set this correctly, but if lsb_release isn't available, you can set it manually:
# - For Debian distributions: jessie, sid, etc...
# - For Ubuntu distributions: xenial, bionic, etc...
# - 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.
DISTRO="$(lsb_release -s -c)"
echo "deb [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
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

sudo apt-get update
sudo apt-get install nodejs
 类似资料: