NodeJS Installation on Linux Print

  • 0

Here are two methods to install Node.js and npm (Node Package Manager) on Ubuntu:

Method 1: Using the Official Ubuntu Repositories

This method is the simplest and recommended approach for most users. The packages in the Ubuntu repositories might be slightly older versions, but they are well-tested and compatible with your Ubuntu system.

  1. Update System Packages:

    Bash
    sudo apt update
    
  2. Install Node.js and npm:

    Bash
    sudo apt install nodejs npm
    

    This command will install the latest version of Node.js and npm available in the Ubuntu repositories.

Method 2: Using Node Version Manager (nvm)

This method offers more flexibility as it allows you to install and manage multiple Node.js versions on your system. It's recommended for developers who need to work with different project requirements.

  1. Install curl (if not already installed):

    Bash
    sudo apt install curl
    
  2. Download and install the nvm installation script:

    Bash
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
    

    Note: Replace v0.39.3 with the latest nvm version number if needed (check the official nvm GitHub repository for updates: https://github.com/nvm-sh/nvm).

  3. Source the nvm configuration file (to make nvm commands available):

    Bash
    source ~/.bashrc
    

    You might need to restart your terminal window for the changes to take effect.

  4. List available Node.js versions:

    Bash
    nvm ls-available
    
  5. Install a specific Node.js version (e.g., 16.19.0):

    Bash
    nvm install 16.19.0
    
  6. Use the installed version (activate it):

    Bash
    nvm use 16.19.0
    

    You can verify the active Node.js version using node -v.

Verifying Installation:

Once you've installed Node.js and npm using either method, you can verify the installation by running the following commands:

Bash
node -v  # This should print the installed Node.js version
npm -v   # This should print the installed npm version
 

Was this answer helpful?

« Back