Friday, September 15, 2023

upgrade nodejs on ubuntu

 To upgrade Node.js on Ubuntu, you can use the Node Version Manager (NVM) or you can manually update it. Here's how to do it using both methods:

Using Node Version Manager (NVM):

  1. Install NVM: If you don't have NVM installed, you can install it using the following commands:

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

    Make sure to replace v0.38.0 with the latest version available on the NVM GitHub repository.

  2. Close and Reopen the Terminal: After installing NVM, close and reopen your terminal or run the following command to load NVM:

    bash
    source ~/.bashrc
  3. Check Available Node.js Versions: You can list the available Node.js versions with the following command:

    bash
    nvm ls-remote
  4. Install the Desired Node.js Version: Choose the Node.js version you want to install and use the following command to install it. Replace x.x.x with the version number you want:

    bash
    nvm install x.x.x
  5. Set Default Node.js Version: To set the newly installed Node.js version as the default, use:

    bash
    nvm alias default x.x.x
  6. Verify the Installation: You can verify that Node.js and npm are properly upgraded by running:

    bash
    node -v npm -v

Manually Updating Node.js:

  1. Remove the Existing Node.js and npm:

    First, uninstall the existing Node.js and npm. You can do this using the package manager. Run the following commands to uninstall Node.js and npm:

    bash
    sudo apt-get remove nodejs sudo apt-get remove npm
  2. Install Node.js and npm using a Package Manager:

    After removing the old versions, you can install the latest Node.js and npm using the package manager. To do this, use the following commands:

    bash
    sudo apt-get update sudo apt-get install nodejs sudo apt-get install npm
  3. Verify the Installation:

    Verify that Node.js and npm are properly upgraded by running:

    bash
    node -v npm -v

This will ensure that you have the latest version of Node.js installed on your Ubuntu system.

No comments:

Post a Comment