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):
Install NVM: If you don't have NVM installed, you can install it using the following commands:
bashcurl -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.Close and Reopen the Terminal: After installing NVM, close and reopen your terminal or run the following command to load NVM:
bashsource ~/.bashrc
Check Available Node.js Versions: You can list the available Node.js versions with the following command:
bashnvm ls-remote
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:bashnvm install x.x.x
Set Default Node.js Version: To set the newly installed Node.js version as the default, use:
bashnvm alias default x.x.x
Verify the Installation: You can verify that Node.js and npm are properly upgraded by running:
bashnode -v npm -v
Manually Updating Node.js:
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:
bashsudo apt-get remove nodejs sudo apt-get remove npm
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:
bashsudo apt-get update sudo apt-get install nodejs sudo apt-get install npm
Verify the Installation:
Verify that Node.js and npm are properly upgraded by running:
bashnode -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