Home > Web Front-end > JS Tutorial > body text

How to install the latest Node.js and NPM on Ubuntu using PPA

不言
Release: 2019-03-26 16:13:03
Original
2839 people have browsed it

Node.js is a platform that runs on Chrome JavaScript, making it easy to build fast, scalable web applications. The latest version of node.js ppa is maintained by its official website. We can add this PPA to your Ubuntu 19.04, 18.04 LTS, 16.04 LTS (Trusty Tahr) and 14.04 LTS (Xenial Xerus) systems and install node.js on Linux VPS using simple commands.

How to install the latest Node.js and NPM on Ubuntu using PPA

To install a specific nodejs version, please refer to Installing a specific Nodejs version using NVM.

Step 1: Add node.js ppa

The node.js package is available in LTS version and current version. You can choose which version to install on your system based on your needs. Let us add the ppa to the system to install nodejs on Ubuntu.

Use current version:

$ sudo apt-get install curl python-software-properties
$ curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
Copy after login

Use LTS version:

$ sudo apt-get install curl python-software-properties
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
Copy after login

For this example used the latest current version and added their ppa to my system .

Step 2: Install node.js on Ubuntu

You can successfully add the node.js ppa to the Ubuntu system. Now use apt get to execute the following command to install node on and ubuntu. This will also install NPM with node.js. This command will also install many other dependent packages on the system.

$ sudo apt-get install nodejs
Copy after login

Step 3: Check node.js and npm versions

After installing node.js, please verify and check the installed version. More details about the current version can be found on the official node.js website.

$ node -v 
v11.12.0
Copy after login

Also, check the NPM version

$ npm -v 
6.7.0
Copy after login

Step 4: Create a demo web server (optional)

This is an optional step. If you want to test node.js installation. Let’s create the file server.js

$ vim server.js
Copy after login

with the “Hello, world!” text and add the following content

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/');
Copy after login

Now use command to start the node application.

$ node server.js
debugger listening on port 5858
Server running at http://127.0.0.1:3000/
Copy after login

You can also enable debugging using the following command to start the application.

$ 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/
Copy after login

The web server has been started on port 3000. Now visit http:// in the browser /127.0.0.1:3000/url. Now, you only need to configure the front-end server for the application.

This article is over here. For more other exciting content, you can follow the ## of the PHP Chinese website #node.js video tutorial column!!!

The above is the detailed content of How to install the latest Node.js and NPM on Ubuntu using PPA. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!