Node.js是一个基于Chrome JavaScript运行的平台,可轻松构建快速,可扩展的网络应用程序。最新版本node.js ppa由其官方网站维护。我们可以将此PPA添加到您的Ubuntu 19.04,18.04 LTS,16.04 LTS(Trusty Tahr)和14.04 LTS(Xenial Xerus)系统,并使用简单命令在Linux VPS上安装node.js.

要安装特定的nodejs版本,请参考使用NVM安装特定的Nodejs版本。
步骤1:添加node.js ppa node.js包在LTS版本和当前版本中可用。可以根据需要选择要在系统上安装的版本。让我们将ppa添加到系统中,以便在Ubuntu上安装nodejs。 使用当前版本: $ sudo apt-get install curl python-software-properties
$ curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash - 使用LTS版本: $ sudo apt-get install curl python-software-properties
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - 对于该示例使用的是最新的当前版本,并将它们的ppa添加到我的系统中。 步骤2:在Ubuntu上安装node.js 可以成功地将node.js ppa添加到Ubuntu系统。现在使用apt get执行下面的命令install node on和ubuntu。这也将安装带有node.js的NPM。此命令还将在系统上安装许多其他依赖包。 $ sudo apt-get install nodejs 步骤3:检查node.js和npm版本 安装node.js之后,请验证并检查已安装的版本。可以在node.js官方网站上找到有关当前版本的更多详细信息。 $ node -v
v11.12.0 另外,检查NPM版本 $ npm -v
6.7.0 步骤4:创建演示Web服务器(可选) 这是一个可选步骤。如果要测试node.js安装。让我们用“你好,世界!“文本”。创建文件server.js $ vim server.js 并添加以下内容 server.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3000/'); 现在使用命令启动node应用程序。 $ node server.js
debugger listening on port 5858
Server running at http://127.0.0.1:3000/ 还可以使用以下命令启用调试来启动应用程序。 $ node --inspect server.js
Debugger listening on ws://127.0.0.1:9229/8976a32b-cf99-457c-85fb-e7288cbadac6
For help see https://nodejs.org/en/docs/inspector
Server running at http://127.0.0.1:3000/ Web服务器已在端口3000上启动。现在在浏览器中访问http://127.0.0.1:3000/url。现在,只需要为应用程序配置前端服务器。 本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注PHP中文网的node.js视频教程栏目!!! 以上就是如何使用PPA在Ubuntu上安装最新的Node.js和NPM的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章! |