Home > Article > Web Front-end > How to install nodejs via npm
npm (Node Package Manager) is a package manager for Node.js, which allows developers to install, upload, manage and share code packages more conveniently. To use npm, of course you need to install Node.js first. Let’s talk about how to install nodejs through npm.
To install nodejs on Windows, you can directly download the Node.js installation package, and then double-click to run it. However, when installing nodejs on macOS or Linux, it is recommended to use the node version management tool to manage and install nodejs.
Before using npm to install nodejs, you need to install nvm (Node Version Manager) first. nvm is a simple Bash script that allows you to easily manage multiple Node.js versions. Through nvm, we can choose the nodejs version we need and switch between it in different projects.
Install nvm using the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
Then, close the terminal and reopen a new terminal window. Enter the following command to check whether nvm is installed successfully:
nvm version
Next, we can use the following command to install any version of nodejs:
nvm install <version>
Among them, <version>
is the required nodejs version number. For example, to install the latest stable version of Node.js, you should enter the following command:
nvm install stable
Alternatively, if you want to install a specific version of Node.js, you can do so with the following command:
nvm install <specific-nodejs-version>
Note that <specific-nodejs-version>
needs to be specified in the format of v14.18.1
or 14.18.1
. If the version you want to install already exists locally, the console will display information similar to the following:
Version <specific-nodejs-version> already installed.
Of course, if you need to uninstall the installed nodejs version, you can use the following command:
nvm uninstall <version>
At this point, we have successfully installed the required nodejs version using npm. Next, you can use Node.js to carry out various types of development work such as web, mobile, and server.
The above is the detailed content of How to install nodejs via npm. For more information, please follow other related articles on the PHP Chinese website!