DEV Community

shamnad-sherief
shamnad-sherief

Posted on

Installing and Managing Different Versions of Node.js with NVM

NVM is a version manager for node.js. Navigating the diverse landscape of Node.js versions can be a daunting task, but with Node Version Manager (NVM), the process becomes effortless.

1. Install NVM: Begin by installing NVM with the provided script:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

Alternatively, reopen the terminal or run source ~/.bashrc to apply changes.

2. Confirm NVM Installation: Check the installed NVM version:

nvm --version
Enter fullscreen mode Exit fullscreen mode

3. Install Node.js: Use NVM to install a specific version of Node.js, for example, the latest LTS version:

nvm install --lts
Enter fullscreen mode Exit fullscreen mode

4. Check Node.js Version: Verify the installed Node.js version:

node --version
Enter fullscreen mode Exit fullscreen mode

5. Set Default Node.js Version (Optional): Optionally, set a default Node.js version using NVM:

nvm alias default <node_version>  
Enter fullscreen mode Exit fullscreen mode

Replace <node_version> with the desired version number.

Additional Commands:

  • Install Latest Release of Node.js: To download, compile, and install the latest release of Node.js, use:

    nvm install node # "node" is an alias for the latest version
    
  • Install Specific Node.js Version: Install a specific version of Node.js by specifying the version number:

    nvm install 14.7.0 # or any other version like 16.3.0, 12.22.1, etc
    
  • List Available Versions: View available Node.js versions with:

    nvm ls-remote
    
  • Use Installed Version: Set the installed Node.js version as active:

    nvm use node
    
  • Get Path to Installed Executable: Obtain the path to the executable of the installed Node.js version:

    nvm which 12.22
    

Links for Further Reference:

Top comments (0)