{"id":100986,"date":"2026-03-21T23:10:07","date_gmt":"2021-08-20T08:02:56","guid":{"rendered":"https:\/\/computingforgeeks.com\/?p=100986"},"modified":"2026-03-21T23:10:17","modified_gmt":"2026-03-21T20:10:17","slug":"install-nodejs-ubuntu-debian","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/install-nodejs-ubuntu-debian\/","title":{"rendered":"Install Node.js 22 LTS on Ubuntu 24.04 \/ Debian 13"},"content":{"rendered":"\n<p>Node.js is a cross-platform JavaScript runtime built on Chrome&#8217;s V8 engine that lets you run JavaScript outside the browser. It powers everything from REST APIs and microservices to full-stack web applications and CLI tools. Node.js 22 LTS (codename &#8220;Jod&#8221;) is the current long-term support release, maintained through April 2027.<\/p>\n\n\n\n<p>This guide covers three methods to install Node.js 22 LTS on Ubuntu 24.04 and Debian 13 &#8211; the NodeSource repository (recommended for production), default apt packages, and nvm for managing multiple versions. We also cover npm and yarn package management plus firewall configuration for Node.js applications.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A server or workstation running Ubuntu 24.04 or Debian 13<\/li>\n\n<li>A user account with sudo privileges<\/li>\n\n<li>Internet connectivity to download packages<\/li>\n\n<li>Ports 3000, 8080, or whichever port your Node.js app uses (if serving traffic)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Install Node.js 22 LTS from NodeSource (Recommended)<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/nodejs.org\/en\" target=\"_blank\" rel=\"noreferrer noopener\">NodeSource<\/a> repository provides the latest Node.js 22 LTS builds packaged for Debian-based systems. This is the recommended method for production servers since you get timely security updates through apt.<\/p>\n\n\n\n<p>First, update your package index and install the required dependencies:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install -y curl gnupg<\/code><\/pre>\n\n\n\n<p>Download and run the NodeSource setup script for Node.js 22:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -fsSL https:\/\/deb.nodesource.com\/setup_22.x | sudo -E bash -<\/code><\/pre>\n\n\n\n<p>The script adds the NodeSource GPG signing key and configures the apt repository. You should see confirmation that the repository was added successfully:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>## Installing the NodeSource Node.js 22.x repo...\n## Populating apt-get cache...\n## Confirming \"noble\" is supported...\n## Adding the NodeSource signing key to your keyring...\n## Creating apt sources list file for the NodeSource Node.js 22.x repo...\n## Running `apt-get update` for you...<\/code><\/pre>\n\n\n\n<p>Now install Node.js 22 LTS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y nodejs<\/code><\/pre>\n\n\n\n<p>Verify the installation by checking the Node.js and npm versions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node --version<\/code><\/pre>\n\n\n\n<p>The output confirms Node.js 22 LTS is installed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>v22.22.1<\/code><\/pre>\n\n\n\n<p>Check the bundled npm version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm --version<\/code><\/pre>\n\n\n\n<p>npm ships bundled with Node.js &#8211; you should see version 10.x or later:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>10.9.2<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Install Node.js from Default APT Repositories<\/h2>\n\n\n\n<p>Ubuntu 24.04 and Debian 13 include Node.js in their default repositories. The version may be older than the latest Node.js 22 LTS, but this method requires no external repositories.<\/p>\n\n\n\n<p>Install Node.js and npm from the default repos:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install -y nodejs npm<\/code><\/pre>\n\n\n\n<p>Check the installed version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nodejs --version<\/code><\/pre>\n\n\n\n<p>The default repository version is typically older than NodeSource. If you need the latest Node.js 22 LTS features, use Method 1 (NodeSource) or Method 3 (nvm) instead.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Install Node.js 22 with nvm (Node Version Manager)<\/h2>\n\n\n\n<p>nvm lets you install and switch between multiple Node.js versions on the same machine. This is ideal for development environments where different projects need different Node.js versions. If you need to <a href=\"https:\/\/computingforgeeks.com\/manage-nodejs-versions-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\">run multiple versions of Node.js<\/a> side by side, nvm is the right tool.<\/p>\n\n\n\n<p>Download and run the nvm install script (v0.40.4 at the time of writing):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -o- https:\/\/raw.githubusercontent.com\/nvm-sh\/nvm\/v0.40.4\/install.sh | bash<\/code><\/pre>\n\n\n\n<p>The script clones the nvm repository to <code>~\/.nvm<\/code> and adds the initialization lines to your shell profile. Reload your shell configuration to make nvm available:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source ~\/.bashrc<\/code><\/pre>\n\n\n\n<p>Verify nvm is working:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nvm --version<\/code><\/pre>\n\n\n\n<p>You should see the nvm version number confirmed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0.40.4<\/code><\/pre>\n\n\n\n<p>Install Node.js 22 LTS using nvm:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nvm install 22<\/code><\/pre>\n\n\n\n<p>nvm downloads and installs the latest Node.js 22 release along with npm:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Downloading and installing node v22.22.1...\nDownloading https:\/\/nodejs.org\/dist\/v22.22.1\/node-v22.22.1-linux-x64.tar.xz...\n######################################################################### 100.0%\nComputing checksum with sha256sum\nChecksums matched!\nNow using node v22.22.1 (npm v10.9.2)<\/code><\/pre>\n\n\n\n<p>Set Node.js 22 as the default version for new shell sessions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nvm alias default 22<\/code><\/pre>\n\n\n\n<p>Confirm the active version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node --version\nnpm --version<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Working with npm &#8211; Node Package Manager<\/h2>\n\n\n\n<p>npm is the default package manager for Node.js. It handles dependency installation, script execution, and package publishing. Here are the essential npm operations you need to know.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Initialize a New Node.js Project<\/h3>\n\n\n\n<p>Create a new project directory and initialize it with a <code>package.json<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir my-app && cd my-app\nnpm init -y<\/code><\/pre>\n\n\n\n<p>The <code>-y<\/code> flag accepts all defaults. This creates a <code>package.json<\/code> that tracks your project dependencies and scripts:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"name\": \"my-app\",\n  \"version\": \"1.0.0\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"keywords\": [],\n  \"author\": \"\",\n  \"license\": \"ISC\",\n  \"description\": \"\"\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install Packages Locally<\/h3>\n\n\n\n<p>Local packages are installed in the project&#8217;s <code>node_modules<\/code> directory and listed in <code>package.json<\/code>. This is the standard approach for project dependencies:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install express<\/code><\/pre>\n\n\n\n<p>For development-only dependencies like testing frameworks or linters:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install --save-dev jest eslint<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install Packages Globally<\/h3>\n\n\n\n<p>Global packages provide CLI tools available system-wide. Use global installs sparingly &#8211; only for tools you run from the command line, not project dependencies:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo npm install -g pm2 nodemon<\/code><\/pre>\n\n\n\n<p>List all globally installed packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm list -g --depth=0<\/code><\/pre>\n\n\n\n<p>The output shows the globally installed packages and their versions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/lib\n\u251c\u2500\u2500 corepack@0.31.0\n\u251c\u2500\u2500 nodemon@3.1.9\n\u251c\u2500\u2500 npm@10.9.2\n\u2514\u2500\u2500 pm2@6.0.5<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Other Useful npm Commands<\/h3>\n\n\n\n<p>Update all packages in a project to their latest compatible versions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm update<\/code><\/pre>\n\n\n\n<p>Remove a package:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm uninstall express<\/code><\/pre>\n\n\n\n<p>Check for outdated packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm outdated<\/code><\/pre>\n\n\n\n<p>Audit your dependencies for known security vulnerabilities:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm audit<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Install Yarn Package Manager<\/h2>\n\n\n\n<p>Yarn is an alternative package manager that some projects prefer for its speed and deterministic installs. Node.js 22 ships with Corepack, which manages Yarn without a separate install step.<\/p>\n\n\n\n<p>Enable Corepack to activate Yarn:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo corepack enable<\/code><\/pre>\n\n\n\n<p>Verify Yarn is available:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yarn --version<\/code><\/pre>\n\n\n\n<p>The version output confirms Yarn is ready to use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1.22.22<\/code><\/pre>\n\n\n\n<p>To use Yarn 4 (Berry) in a project, set the version inside the project directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yarn set version stable<\/code><\/pre>\n\n\n\n<p>Basic Yarn commands mirror npm closely:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yarn init -y\nyarn add express\nyarn add --dev jest\nyarn remove express<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Configure Firewall for Node.js Applications<\/h2>\n\n\n\n<p>If your Node.js application serves traffic, you need to open the appropriate port in the firewall. Ubuntu 24.04 and Debian 13 use UFW (Uncomplicated Firewall).<\/p>\n\n\n\n<p>For a typical Node.js app running on port 3000:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow 3000\/tcp<\/code><\/pre>\n\n\n\n<p>If your app uses port 8080:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow 8080\/tcp<\/code><\/pre>\n\n\n\n<p>Enable UFW if it is not already active:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw enable<\/code><\/pre>\n\n\n\n<p>Verify the firewall rules are in place:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw status<\/code><\/pre>\n\n\n\n<p>The output shows the allowed ports and their status:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Status: active\n\nTo                         Action      From\n--                         ------      ----\n22\/tcp                     ALLOW       Anywhere\n3000\/tcp                   ALLOW       Anywhere\n8080\/tcp                   ALLOW       Anywhere\n22\/tcp (v6)                ALLOW       Anywhere (v6)\n3000\/tcp (v6)              ALLOW       Anywhere (v6)\n8080\/tcp (v6)              ALLOW       Anywhere (v6)<\/code><\/pre>\n\n\n\n<p>For production deployments, run your Node.js app behind a reverse proxy like <a href=\"https:\/\/computingforgeeks.com\/install-configure-nginx-ubuntu-debian\/\" target=\"_blank\" rel=\"noreferrer noopener\">Nginx<\/a> rather than exposing the Node.js port directly. The reverse proxy handles SSL termination, load balancing, and static file serving. You can pair it with a process manager like PM2 to keep your app running across restarts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create a Test Node.js Application<\/h2>\n\n\n\n<p>To confirm everything works end to end, create a simple HTTP server. Create a file called <code>server.js<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi server.js<\/code><\/pre>\n\n\n\n<p>Add the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const http = require('http');\n\nconst hostname = '0.0.0.0';\nconst port = 3000;\n\nconst server = http.createServer((req, res) => {\n  res.statusCode = 200;\n  res.setHeader('Content-Type', 'text\/plain');\n  res.end('Node.js 22 LTS is running on Ubuntu\/Debian\\n');\n});\n\nserver.listen(port, hostname, () => {\n  console.log(`Server running at http:\/\/${hostname}:${port}\/`);\n});<\/code><\/pre>\n\n\n\n<p>Start the server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node server.js<\/code><\/pre>\n\n\n\n<p>The server starts listening on port 3000:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Server running at http:\/\/0.0.0.0:3000\/<\/code><\/pre>\n\n\n\n<p>Open a second terminal and test with curl:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl http:\/\/localhost:3000<\/code><\/pre>\n\n\n\n<p>You should get back the response confirming Node.js is working:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Node.js 22 LTS is running on Ubuntu\/Debian<\/code><\/pre>\n\n\n\n<p>Press <code>Ctrl+C<\/code> to stop the server. For a proper development workflow, consider setting up <a href=\"https:\/\/computingforgeeks.com\/how-to-install-visual-studio-code-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Visual Studio Code on Ubuntu<\/a> as your editor with the Node.js extension pack.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Uninstall Node.js<\/h2>\n\n\n\n<p>If you installed Node.js via NodeSource or the default repos and need to remove it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt remove --purge nodejs\nsudo rm -f \/etc\/apt\/sources.list.d\/nodesource.list\nsudo rm -f \/etc\/apt\/keyrings\/nodesource.gpg\nsudo apt autoremove<\/code><\/pre>\n\n\n\n<p>If you used nvm, uninstall the Node.js version and optionally remove nvm itself:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nvm deactivate\nnvm uninstall 22\nrm -rf ~\/.nvm<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Node.js 22 LTS is now installed on your Ubuntu 24.04 or Debian 13 system. The NodeSource repository gives you the latest stable releases with standard apt updates, while nvm is better suited for development machines where you juggle multiple Node.js versions. You can also manage containers for your Node.js apps &#8211; see how to <a href=\"https:\/\/computingforgeeks.com\/install-docker-and-run-docker-containers-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">install Docker on Ubuntu<\/a> for container-based deployments.<\/p>\n\n\n\n<p>For production deployments, put your Node.js app behind Nginx as a reverse proxy, use PM2 as a process manager, and enable SSL with Let&#8217;s Encrypt. Monitor your application logs and set up <a href=\"https:\/\/computingforgeeks.com\/install-and-configure-ssh-server-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">SSH access<\/a> for secure remote management.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Node.js is a cross-platform JavaScript runtime built on Chrome&#8217;s V8 engine that lets you run JavaScript outside the browser. It powers everything from REST APIs and microservices to full-stack web applications and CLI tools. Node.js 22 LTS (codename &#8220;Jod&#8221;) is the current long-term support release, maintained through April 2027. This guide covers three methods to &#8230; <a title=\"Install Node.js 22 LTS on Ubuntu 24.04 \/ Debian 13\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/install-nodejs-ubuntu-debian\/\" aria-label=\"Read more about Install Node.js 22 LTS on Ubuntu 24.04 \/ Debian 13\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":101723,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,690,299,50,81],"tags":[763],"class_list":["post-100986","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debian","category-dev","category-how-to","category-linux-tutorials","category-ubuntu","tag-node-js"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/100986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=100986"}],"version-history":[{"count":1,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/100986\/revisions"}],"predecessor-version":[{"id":163323,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/100986\/revisions\/163323"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/101723"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=100986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=100986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=100986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}