Debian安装node.js

介绍

Node.js是一个能够在服务器端运行JavaScript的开放源代码、跨平台JavaScript运行环境。Node.js由Node.js基金会持有和维护,并与Linux基金会有合作关系。Node.js采用Google开发的V8运行代码,使用事件驱动、非阻塞和异步输入输出模型等技术来提高性能,可优化应用程序的传输量和规模。

安装

通过包管理器安装

Debian在其默认存储库中包含一个Node.js版本。所以直接用apt安装即可。

1
apt-get install nodejs -y

检查安装的版本

1
nodejs -v

通过NodeSource安装

系统本身的存储库里有nodejs,但是版本较低,我们需要安装较新的版本,所以我们就得通过NodeSource来安装新的版本了。

NodeSource将保持对Debian的稳定版,测试版和不稳定版的支持,因为发布周期较长,相当多的用户运行不稳定。

Debian 支持版本:

  • Debian 8 / oldstable (Jessie)
  • Debian 9 / stable (Stretch)
  • Debian 10 / testing (Buster)
  • Debian unstable (Sid)

安装说明

Node.js v12.x:

1
2
3
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs

Node.js v11.x:

1
2
3
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_11.x | bash -
apt-get install -y nodejs

Node.js v10.x:

1
2
3
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt-get install -y nodejs

Node.js v8.x:

1
2
3
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_8.x | bash -
apt-get install -y nodejs

Node.js v6.x:

1
2
3
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_6.x | bash -
apt-get install -y nodejs

可选:安装构建工具

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

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