Home >Web Front-end >Front-end Q&A >Install nodejs and npm under linux
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.
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.
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.
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.
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
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!