Linux安装Node.js与Npm

如何在CentOS,RHEL和Fedora中安装Node.js 14
最新版本的Node.js和NPM可从官方的NodeSource Enterprise Linux存储库中获得,该资源库由Nodejs网站维护,您需要将其添加到系统中才能安装最新的Nodejs和NPM软件包。

重要提示:如果您正在运行RHEL 6或CentOS 6的较旧版本,则可能需要阅读有关在较旧发行版上运行Node.js的信息。

在RHEL,CentOS和Fedora中安装NodeJS 14.x

要为最新版本的Node.js 14.x添加存储库,请以超级用户或非超级用户身份使用以下命令。

-------------- 以root用户身份 --------------

curl -sL https://rpm.nodesource.com/setup_14.x | bash -

-------------- 具有root特权的用户 --------------

$ curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -

在RHEL,CentOS和Fedora上安装NodeJS 12.x

如果要安装NodeJS 12.x,请添加以下存储库。

-------------- 以root用户身份 --------------

curl -sL https://rpm.nodesource.com/setup_12.x | bash -

-------------- 具有root特权的用户 --------------

$ curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -

在RHEL,CentOS和Fedora上安装NodeJS 10.x

如果要安装NodeJS 10.x,请添加以下存储库。

-------------- 以root用户身份 --------------

curl -sL https://rpm.nodesource.com/setup_10.x | bash -

-------------- 具有root特权的用户 --------------

$ curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -

接下来,您现在可以使用以下命令在系统上安装Nodejs和NPM:

yum -y install nodejs

或者

dnf -y install nodejs

可选:有一些开发工具,例如gcc-c++,使您需要在系统上安装这些工具,以便从npm构建原生插件。

yum install gcc-c++ make

或者

yum groupinstall 'Development Tools'

如何在Debian,Ubuntu和Linux Mint中安装Node.js 14

还可以从官方的NodeSource Enterprise Linux存储库中获得最新版本的Node.js和NPM,该资源库由Nodejs网站维护,您需要将其添加到系统中才能安装最新的Nodejs和NPM软件包。

在Debian,Ubuntu和Linux Mint中安装NodeJS 14.x

------- 在Ubuntu和Linux Mint上 -------

$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

$ sudo apt-get install -y nodejs

------- 在Debian上 -------

curl -sL https://deb.nodesource.com/setup_14.x | bash -

apt-get install -y nodejs

在Debian,Ubuntu和Linux Mint中安装NodeJS 12.x

------- 在Ubuntu和Linux Mint上 -------

$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

$ sudo apt-get install -y nodejs

------- 在Debian上 -------

curl -sL https://deb.nodesource.com/setup_12.x | bash -

apt-get install -y nodejs

在Debian,Ubuntu和Linux Mint中安装NodeJS 10.x

------- 在Ubuntu和Linux Mint上-------

$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

$ sudo apt-get install -y nodejs

------- 在Debian上 -------

curl -sL https://deb.nodesource.com/setup_10.x | bash -

apt-get install -y nodejs

可选:有一些开发工具,例如gcc-c++,使您需要在系统上安装这些工具,以便从npm构建本机插件。

$ sudo apt-get install -y build-essential

在Linux中测试最新的Node.js和NPM

要对nodejs和NPM进行简单测试,您可以使用以下命令检查系统上安装的版本:

在RHEL,CentOS和Fedora上

node --version

npm --version

在Debian,Ubuntu和Linux Mint上

$ node --version

$ npm --version

就是这样,Nodejs和NPM现在已安装并可以在您的系统上使用。

辰鬼丫
原文地址:https://www.cnblogs.com/Acechengui/p/14095930.html