Home  >  Article  >  Web Front-end  >  Install nodejs and npm under linux

Install nodejs and npm under linux

王林
王林Original
2023-05-25 13:21:401963browse

Linux is a commonly used operating system, and Node.js is a JavaScript running environment that has become increasingly popular in recent years. Installing Node.js and npm under the Linux system can bring more convenience to our development work. This article will introduce how to install Node.js and npm under Linux system.

Step 1: Install Node.js

First you need to prepare the Node.js installation package. You can download the latest version of Node.js installation package from the official website of Node.js (https://nodejs.org/en/download/).

After the download is completed, enter the download folder through the terminal and unzip the file. In the decompressed folder, enter the following command to install:

$ ./configure
$ make
$ sudo make install

This command will perform the following operations:

  • configure: used to generate Makefile files , for subsequent compilation operations.
  • make: Compile Node.js source code.
  • sudo make install: Install the compiled Node.js into the system.

After the installation is complete, you can check the Node.js version through the following command:

$ node -v

If the version number of Node.js is output, it means that Node.js has been installed successfully.

Step 2: Install npm

npm is the default package manager for Node.js, used to install, upgrade and manage Node.js modules. When installing Node.js, npm will also be installed. If you need to install npm separately, you can do it with the following command:

$ sudo apt-get install npm

After the installation is complete, you can check the npm version with the following command:

$ npm -v

If the version number of npm is output, it means npm Installed successfully.

Use npm to install the module

After installing Node.js and npm, you can install and manage the Node.js module through npm. Enter the following command in the terminal:

$ npm install <module-name>

where f22ca2e2c07e8b5ec6c193834fda2b41 is the name of the module that needs to be installed. For example, to install the Express module, you can enter the following command:

$ npm install express

npm will automatically download and install the Express module and its dependencies from the npm repository.

Upgrade Node.js and npm

Node.js and npm have regular updated versions, which can be upgraded through the following command:

$ sudo npm install -g n
$ sudo n latest
$ sudo npm install -g npm

This command will perform the following operations :

  • npm install -g n: Install n module, used to manage the version of Node.js.
  • n latest: Upgrade Node.js to the latest version.
  • npm install -g npm: Upgrade npm to the latest version.

After the upgrade is completed, you can check the current version number through the following command:

$ node -v
$ npm -v

Summary

Through the above steps, we can install Node.js under the Linux system and npm, and install and manage Node.js modules through npm. Of course, there are other methods and tools that can help us better install and manage Node.js. During use, you can choose the appropriate method to meet your needs.

The above is the detailed content of Install nodejs and npm under linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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