Installing Node.js and Using a Specific Version with NVM

Node.js Installation

Installing Node.js

To install Node.js, follow these steps. The instructions are applicable for both Linux (especially Ubuntu) and Windows operating systems.

Ubuntu (and other Debian-based systems)

  1. Update your repository and install necessary packages:

    sudo apt update sudo apt install -y curl software-properties-common
  2. Add the NodeSource repository:

    curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
  3. Install Node.js:

    sudo apt-get install -y nodejs
  4. Verify the installation:

    node -v npm -v

Windows

  1. Visit the official Node.js website and download the latest version.

  2. Run the downloaded installer and follow the steps in the setup wizard.

  3. Verify the installation:

    node -v npm -v

MacOS

  1. Install using Homebrew:

    brew update brew install node@16
  2. Configure your path:

    echo 'export PATH="/usr/local/opt/node@16/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
  3. Verify the installation:

    node -v npm -v

Using NVM (Node Version Manager) to Switch to a Specific Node.js Version (16.20)

Switching to Node.js version 16.20.0 using NVM is straightforward. Follow these steps:

  1. Install NVM if not already installed.
  2. Install latest Node.js version:
  3. nvm install node
  4. Or install a specific Node.js version:
  5. nvm install 16.20.0
  6. Verify the installation:
  7. node -v npm -v
  8. List all installed node versions:
  9. nvm ls
  10. Use Node.js version 16.20.0:
  11. nvm use 16.20.0
  12. Set the default Node.js version:
  13. nvm alias default 16.20.0
  14. Use the latest installedNode.js version when needed:
  15. nvm use node

After installing Node.js version 16.20, running the npm -v command should display npm version 8.19.4, as it is compatible with Node.js 16. This is expected, and you can continue using npm version 8.19.4 without issues.




Comments