{"id":13370,"date":"2024-02-26T01:34:18","date_gmt":"2024-02-25T22:34:18","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=13370"},"modified":"2024-02-26T01:34:19","modified_gmt":"2024-02-25T22:34:19","slug":"how-to-install-node-js-on-ubuntu-22-04","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/how-to-install-node-js-on-ubuntu-22-04\/","title":{"rendered":"How to Install Node.js on Ubuntu 22.04"},"content":{"rendered":"\n
Node.js is a powerful runtime environment that allows you to run JavaScript<\/a> on the server side, making it an essential tool for web developers. If you’re using Ubuntu 22.04 and want to harness the capabilities of Node.js for your projects, this guide will walk you through the installation process step by step.<\/p>\n\n\n\n Before you start installing Node.js<\/a> on your Ubuntu 22.04 system, make sure you have the following:<\/p>\n\n\n\n The easiest way to install Node.js is by using the official Ubuntu<\/a> repositories. This method provides a stable version, but it may not always be the latest. To install Node.js this way, follow these steps:<\/p>\n\n\n\n Step 1: Update your package repository<\/strong>.<\/p>\n\n\n\n This command will update the package repository to ensure that you have the latest information on available packages.<\/p>\n\n\n\n Step 2: Install Node.js and npm<\/strong>.<\/p>\n\n\n\n You can install Node.js and npm using the following command:<\/p>\n\n\n\n This command will install both Node.js and the Node Package Manager (npm).<\/p>\n\n\n\n Step 3: Verify the installation<\/strong>.<\/p>\n\n\n\n To check if Node.js and npm have been installed correctly, run the following commands:<\/p>\n\n\n\n You should see the installed versions of Node.js and npm, confirming that the installation was successful.<\/p>\n\n\n\n NodeSource provides more up-to-date Node.js versions and offers flexibility in selecting specific versions. Here’s how to install Node.js using NodeSource:<\/p>\n\n\n\n Step 1: Install the required software<\/strong>.<\/p>\n\n\n\n Before adding the NodeSource <\/strong>repository, make sure you have the necessary software installed. This will allow you to add and update repositories via HTTPS:<\/p>\n\n\n\n Step 2: Create deb repository<\/strong>.<\/p>\n\n\n\n NodeSource <\/strong>maintains a repository for Node.js. To add it to your system, run the following command, replacing Optional<\/strong><\/em>: Step 3: Install Node.js and npm<\/strong>.<\/p>\n\n\n\n After adding the NodeSource repository, install Node.js and npm with the following command:<\/p>\n\n\n\n Step 4: Verify the installation<\/strong>.<\/p>\n\n\n\n To confirm the successful installation of Node.js and npm, run:<\/p>\n\n\n\n You should see the installed versions displayed on the screen.<\/p>\n\n\n\nPrerequisites<\/h2>\n\n\n\n
\n
Method 1: Installing Node.js using the Official Ubuntu Repositories<\/h2>\n\n\n\n
$ sudo apt update<\/code><\/pre>\n\n\n\n
$ sudo apt install nodejs npm<\/code><\/pre>\n\n\n\n
$ node -v\n$ npm -v<\/code><\/pre>\n\n\n\n
Method 2: Installing Node.js using NodeSource<\/h2>\n\n\n\n
$ sudo apt-get update\n$ sudo apt install -y ca-certificates curl gnupg software-properties-common\n$ sudo mkdir -p \/etc\/apt\/keyrings\n$ curl -fsSL https:\/\/deb.nodesource.com\/gpgkey\/nodesource-repo.gpg.key | sudo gpg --dearmor -o \/etc\/apt\/keyrings\/nodesource.gpg<\/code><\/pre>\n\n\n\n
16.x<\/code> with your desired Node.js version:<\/p>\n\n\n\n
$ NODE_MAJOR=20\n$ 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<\/code><\/pre>\n\n\n\n
NODE_MAJOR<\/code> can be changed depending on the version you need.<\/p>\n\n\n\n
NODE_MAJOR=16\nNODE_MAJOR=18\nNODE_MAJOR=20\nNODE_MAJOR=21<\/code><\/pre>\n\n\n\n
$ sudo apt-get update\n$ sudo apt-get install nodejs -y<\/code><\/pre>\n\n\n\n
$ node -v\n$ npm -v<\/code><\/pre>\n\n\n\n
Uninstall
nodejs<\/code> Ubuntu & Debian packages<\/h3>\n\n\n\n