📜  nvm linux - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:44:50.258000             🧑  作者: Mango

NVM (Node Version Manager) for Linux

Introduction

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.

Prerequisites

Before installing NVM, make sure you have the following dependencies installed on your Linux system:

  • curl command-line tool for downloading files
  • wget command-line tool for downloading files
  • build-essential package for compiling source code

You can install these dependencies by running the following command:

sudo apt-get install curl wget build-essential
Installation

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.

Usage
List available Node.js versions

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.

Install a specific Node.js version

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).

Switch between Node.js versions

To switch between different installed versions of Node.js, use the following command:

nvm use <version>

Replace <version> with the desired Node.js version.

Set default 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.

Use a specific Node.js version for a project

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.

Conclusion

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.