📅  最后修改于: 2023-12-03 14:44:50.258000             🧑  作者: Mango
NVM is a command-line tool that allows developers to easily manage multiple installations of Node.js on Linux. It provides the flexibility to switch between different versions of Node.js as per the project requirements. This guide will walk you through the installation and usage of NVM on a Linux system.
Before installing NVM, make sure you have the following dependencies installed on your Linux system:
curl
command-line tool for downloading fileswget
command-line tool for downloading filesbuild-essential
package for compiling source codeYou can install these dependencies by running the following command:
sudo apt-get install curl wget build-essential
To install NVM on your Linux system, open a terminal and run the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
After the installation is complete, close and reopen the terminal to start using NVM.
To list all the available versions of Node.js that can be installed using NVM, run the following command:
nvm ls-remote
The command will display a list of all the Node.js versions, along with the latest stable release.
To install a specific version of Node.js, run the following command:
nvm install <version>
Replace <version>
with the desired version of Node.js (e.g., 14.17.5
).
To switch between different installed versions of Node.js, use the following command:
nvm use <version>
Replace <version>
with the desired Node.js version.
To set a default Node.js version that will be used when opening a new terminal window, run the following command:
nvm alias default <version>
Replace <version>
with the desired Node.js version.
To use a specific Node.js version for a project, create a .nvmrc
file in the project's root directory and specify the desired Node.js version inside it. For example:
echo "14.17.5" > .nvmrc
After creating the .nvmrc
file, navigate to the project's directory in the terminal and run nvm use
. NVM will automatically detect the .nvmrc
file and switch to the specified Node.js version.
NVM is a powerful tool for managing multiple Node.js installations on a Linux system. It provides the flexibility to easily switch between different Node.js versions based on project requirements. By following this guide, you should now be able to install and use NVM effectively on your Linux machine.
For more information on NVM and its features, refer to the official documentation.