The NodeSource PPA provides the latest stable Node.js releases. To install the latest version (currently v20.6.1), run the following commands:
Update Package List:
sudo apt-get update
/sudo apt update
- This command updates the list of available packages from the repositories.
Install Dependencies:
sudo apt-get install -y ca-certificates curl gnupg
- Installs necessary dependencies like certificates, curl, and gnupg.
Create Keyring Directory:
sudo mkdir -p /etc/apt/keyrings
- Creates a directory for storing GPG keys.
Add Node.js GPG Key:
bashCopy codecurl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
- Fetches the Node.js GPG key and stores it in the keyring directory.
Set Node.js Version:
NODE_MAJOR=20
- Sets the desired Node.js version (in this case, version 20).
Add Node.js Repository:
bashCopy codeecho "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
- Adds the Node.js repository to the sources list.
Update Package List Again:
sudo apt-get update
- Refreshes the package list to include the newly added Node.js repository.
Install Node.js:
sudo apt-get install -y nodejs
- Finally, installs Node.js and its package manager, npm.
These commands ensure that you have the latest Node.js version installed on your Ubuntu system. Make sure to update the version number (NODE_MAJOR) as needed for your project.
IF you want to just copy and paste . Here is the code
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install -y nodejs
Check Version of node.js
node -v
For more Contents :
Follow me on my Linkedn id:https://www.linkedin.com/in/kushagra746/