📜  homebrew nvm install - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:15:32.425000             🧑  作者: Mango

Homebrew NVM Install - Shell-Bash
Introduction

As a programmer, managing multiple versions of Node.js on your machine can be quite challenging. Homebrew is a package manager for macOS that simplifies the installation of various software including Node.js. NVM (Node Version Manager) is a command-line tool that allows you to install and switch between different versions of Node.js effortlessly. This guide will walk you through the steps to install NVM using Homebrew and provide code snippets in markdown format.

Prerequisites

Before we begin, make sure you have Homebrew installed on your macOS. If you don't have Homebrew installed, you can install it by executing the following command in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Steps
  1. Open a terminal and run the following command to install NVM using Homebrew:

    brew install nvm
    

    This command will install NVM (Node Version Manager) on your macOS.

  2. After the installation, you need to configure your shell to use NVM. Run the following command to add the necessary configuration to your shell profile (e.g., ~/.bashrc, ~/.bash_profile, or ~/.zshrc):

    echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.your_shell_profile
    echo '. "/usr/local/opt/nvm/nvm.sh"' >> ~/.your_shell_profile
    

    Replace ~/.your_shell_profile with the path to your shell profile (e.g., ~/.bashrc, ~/.bash_profile, or ~/.zshrc).

  3. To start using NVM, reload your shell profile by running the following command:

    source ~/.your_shell_profile
    
  4. Now, you can install specific versions of Node.js using NVM. To install the latest stable version of Node.js, run the following command:

    nvm install node
    

    This will install the latest stable version of Node.js.

  5. To install a specific version of Node.js, execute the following command:

    nvm install <version>
    

    Replace <version> with the desired Node.js version (e.g., 14.17.0, 12.22.1, etc.).

  6. After installing a version of Node.js, you can use it by running the following command:

    nvm use <version>
    

    Replace <version> with the Node.js version you want to use.

  7. To list all installed versions of Node.js on your machine, use the following command:

    nvm ls
    
Conclusion

Congratulations! You have successfully installed NVM using Homebrew and learned how to manage multiple versions of Node.js on your macOS. Now you can easily switch between different Node.js versions based on your project requirements. Happy coding!