Skip to main content

Install Nodejs on ubuntu

· 2 min read
Sivabharathy

To install a specific version of Node.js on Ubuntu 24.04, you can use the NodeSource binary distributions. Here are the steps to do so:

  1. Update your package index:

    sudo apt update
  2. Install the required dependencies:

    sudo apt install curl software-properties-common
  3. Add the NodeSource repository:

    • To install a specific version, such as Node.js 16, use:
      curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
  4. Install Node.js:

    sudo apt install nodejs
  1. Verify the installation:
    node -v
    npm -v

These steps will install the specified version of Node.js along with npm. If you need a different version, replace setup_16.x in the URL with the appropriate version number (e.g., setup_14.x for Node.js 14).

If you need to manage multiple versions of Node.js, consider using nvm (Node Version Manager):

  1. Install nvm:

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

    export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
  3. Install a specific Node.js version:

    nvm install 16
  4. Set the default Node.js version:

    nvm use 16
    nvm alias default 16
  5. Verify the installation:

    node -v
    npm -v

Using nvm is particularly useful if you frequently switch between different Node.js versions.