{"id":15432,"date":"2019-02-17T12:37:37","date_gmt":"2019-02-17T12:37:37","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=15432"},"modified":"2026-03-10T10:13:02","modified_gmt":"2026-03-10T10:13:02","slug":"how-to-install-nodejs-ubuntu","status":"publish","type":"post","link":"\/uk\/tutorials\/how-to-install-nodejs-ubuntu","title":{"rendered":"How to install node.js on Ubuntu automatically and manually"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>Node.js is a runtime environment that provides software components and interfaces to allow JavaScript code to run properly. Setting it up in the host server is essential if your web application uses the programming language.<\/p><p>In this tutorial, you will learn how to install Node.js on Ubuntu virtual private server (VPS). We will cover two ways to do so &mdash; automatically by using the Hostinger operating system template and manually via command input.<\/p><p>We will also explore three methods for manual installation &ndash; using the Ubuntu repository, NodeSource, and Node Version Manager. These are helpful if you want to set up a specific Node.js version.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1024\" height=\"283\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet-1024x283.png\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet-1536x425.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet-300x83.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet-150x41.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet-768x212.png 768w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-prerequisites-for-installing-node-js-on-ubuntu\">Prerequisites for Installing Node.js on Ubuntu<\/h2><p>Before installing <a href=\"\/uk\/tutorials\/what-is-node-js\">Node.js<\/a>, ensure your VPS supports Ubuntu since the installation commands might differ on other distributions. Preferably, use a newer version like<strong> 22.04 <\/strong>or later to ensure proper compatibility.<\/p><p>Moreover, make sure you can connect to your server remotely via a <a href=\"\/uk\/tutorials\/ssh-tutorial-how-does-ssh-work\">secure shell<\/a> (SSH) or other protocols. Your local computer must also have the PuTTY SSH client installed to access the VPS. Alternatively, MacOS and Linux users can use Terminal.<\/p><p>If you don&rsquo;t have a hosting plan, we recommend purchasing Hostinger VPS. It supports numerous software solutions and offers remote access via SSH. Our <strong>Browser terminal<\/strong> also lets users connect to their server easily via their web browsers.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/uk\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner-1024x300.png\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>Before getting into the steps, we will create a new account for your Ubuntu server since using the default <strong>root<\/strong> user during the installation can be risky if you are not careful. After connecting to your VPS <a href=\"\/uk\/tutorials\/how-to-use-putty-ssh\">using an SSH client like PuTTY<\/a> or Terminal, run the following:<\/p><pre class=\"wp-block-preformatted\">adduser your-preferred-username<\/pre><p>Enter the new user&rsquo;s password and other details. Then, grant the account <strong>sudo<\/strong> privileges to allow it to run administrative commands:<\/p><pre class=\"wp-block-preformatted\">usermod -a -G sudo your-preferred-username<\/pre><p>Now, use this new user whenever you connect to the server via SSH. If you access the VPS as <strong>root<\/strong>, switch to the account using this command before doing any management task:<\/p><pre class=\"wp-block-preformatted\">su your-preferred-username<\/pre><h2 class=\"wp-block-heading\" id=\"h-how-to-install-node-js-on-ubuntu-automatically\">How to Install Node.js on Ubuntu Automatically<\/h2><p>Hostinger users can easily install Node.js using our VPS operating system template. They can configure Ubuntu, the JavaScript runtime, and dependencies in one click via their web browsers.<\/p><p><div><p class=\"important\"><strong>Important!<\/strong> Before installing an operating system template, <a href=\"https:\/\/support.hostinger.com\/en\/articles\/1583232-how-to-back-up-or-restore-a-vps-server\" target=\"_blank\" rel=\"noopener\">back up your VPS<\/a> files since the process will wipe your data permanently.<\/p><\/div>\n\n\n\n<\/p><p>In addition to simplifying the process, this template makes the installation safer since you won&rsquo;t run the wrong commands that might cause issues. Here&rsquo;s how to do so:<\/p><ol class=\"wp-block-list\">\n<li>Log in to hPanel<strong> <\/strong>and select<strong> VPS<\/strong> from the top menu.<\/li>\n\n\n\n<li>Click <strong>Manage<\/strong> next to the VPS you want to install Node.js.<\/li>\n\n\n\n<li>Navigate to the sidebar &rarr;<strong> Settings<\/strong> &rarr; <strong>OS &amp; Panel<\/strong> &rarr; <strong>Operating System<\/strong>.<\/li>\n<\/ol><figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/10\/the-vps-operating-system-configuration-menu-in-hpanel-1024x491-1.png\"><img decoding=\"async\" width=\"1024\" height=\"491\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/10\/the-vps-operating-system-configuration-menu-in-hpanel-1024x491-1.png\" alt=\"The VPS operating system configuration menu in hPanel\" class=\"wp-image-117034\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/10\/the-vps-operating-system-configuration-menu-in-hpanel-1024x491-1.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/10\/the-vps-operating-system-configuration-menu-in-hpanel-1024x491-1-300x144.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/10\/the-vps-operating-system-configuration-menu-in-hpanel-1024x491-1-150x72.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/10\/the-vps-operating-system-configuration-menu-in-hpanel-1024x491-1-768x368.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><ol start=\"4\" class=\"wp-block-list\">\n<li>On the operating system configuration page, click <strong>Applications<\/strong><\/li>\n\n\n\n<li>Select the <strong>OpenLiteSpeed and Node.js<\/strong> template.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69dfa62bd484f\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1024\" height=\"322\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/the-ubuntu-with-openlitespeed-and-nodejs-template-in-hpanel-1-1024x322.png\" alt=\"The Ubuntu with OpenLiteSpeed and Node.js template in hPanel\" class=\"wp-image-109976\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/the-ubuntu-with-openlitespeed-and-nodejs-template-in-hpanel-1-1024x322.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/the-ubuntu-with-openlitespeed-and-nodejs-template-in-hpanel-1-300x94.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/the-ubuntu-with-openlitespeed-and-nodejs-template-in-hpanel-1-150x47.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/the-ubuntu-with-openlitespeed-and-nodejs-template-in-hpanel-1-768x241.png 768w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/the-ubuntu-with-openlitespeed-and-nodejs-template-in-hpanel-1.png 1460w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><ol start=\"6\" class=\"wp-block-list\">\n<li>Scroll down and click<strong> Change OS<\/strong>.&nbsp;<\/li>\n\n\n\n<li>Check the confirmation box to acknowledge the data deletion. Click <strong>Next<\/strong>.<\/li>\n\n\n\n<li>Enter a new <strong>Root password <\/strong>and click<strong> Confirm<\/strong>.<\/li>\n<\/ol><p>Wait a few minutes until the installation process is complete. That&rsquo;s it! Now, you can start deploying JavaScript applications on your VPS.<\/p><p>If you need other software in addition to Node.js, use the<strong> MEAN<\/strong> or <strong>MEVN <\/strong>templates instead. They will also automatically install the <strong>Mongo.DB <\/strong>database and a framework like <strong>Angular<\/strong> or <strong>Vue.js<\/strong>, depending on the stack. <\/p><p>We also have other OS templates that come with Node.js. To list them, you can ask Kodee, our <a href=\"\/blog\/vps-ai-assistant\">AI assistant<\/a>, &ldquo;List available OS templates with Node.js for my VPS.&rdquo;<\/p><p>Note that you can&rsquo;t install a specific Node.js version or another web server when using the operating system template. If you need to do so, select<strong> Plain OS <\/strong>and configure Node.js manually, which we will cover later.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69dfa62bd5538\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1024\" height=\"501\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/a-plain-ubuntu-operating-system-template-in-hpanel-1024x501.png\" alt=\"A plain Ubuntu operating system template in hPanel\" class=\"wp-image-109978\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/a-plain-ubuntu-operating-system-template-in-hpanel-1024x501.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/a-plain-ubuntu-operating-system-template-in-hpanel-300x147.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/a-plain-ubuntu-operating-system-template-in-hpanel-150x73.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/a-plain-ubuntu-operating-system-template-in-hpanel-768x376.png 768w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/a-plain-ubuntu-operating-system-template-in-hpanel.png 1460w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-how-to-install-node-js-on-ubuntu-manually\">How to Install Node.js on Ubuntu Manually<\/h2><p>In this section, we will explain three methods of installing Node.js on Ubuntu using <a href=\"\/uk\/tutorials\/linux-commands\">Linux commands<\/a>, each suitable for configuring different versions. Before proceeding, ensure you have connected to your VPS using a superuser account.<\/p><h3 class=\"wp-block-heading\" id=\"h-how-to-install-node-js-from-ubuntu-repository\">How to Install Node.js from Ubuntu Repository<\/h3><p>The simplest way to install Node.js manually is to use your system&rsquo;s default repository. However, you can&rsquo;t install a particular version and are limited only to the one your Ubuntu operating system offers.<\/p><p>You might also not get the newest Node.js since package availability in the Ubuntu repository depends on the developer&rsquo;s update cycle. It can be a problem for an older Ubuntu installation since it might have outdated ones.<\/p><p>Since we will use <strong>Ubuntu 22.04<\/strong>, we should be able to install a more recent version of Node.js. Here are the steps:<\/p><ol class=\"wp-block-list\">\n<li>Update your Ubuntu&rsquo;s repository to ensure you get the latest available version:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt update<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Install Node.js from the local Ubuntu repository using this command. Confirm installation by pressing <strong>Y<\/strong> and <strong>Enter<\/strong>:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt install nodejs<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Configure the Node Package Manager (NMP), which you will use to manage Node.js and JavaScript dependencies:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt install npm<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Check Node.js and NPM version numbers to verify that both are installed correctly by running these commands subsequently:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo nodejs -v&nbsp;<br><br>sudo npm -v<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69dfa62bd64b7\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"960\" height=\"88\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/command-line-interface-returns-nodejs-and-npm-version-numbers.png\" alt=\"Command-line interface returns Node.js and NPM version numbers\" class=\"wp-image-109979\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/command-line-interface-returns-nodejs-and-npm-version-numbers.png 960w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/command-line-interface-returns-nodejs-and-npm-version-numbers-300x28.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/command-line-interface-returns-nodejs-and-npm-version-numbers-150x14.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/command-line-interface-returns-nodejs-and-npm-version-numbers-768x70.png 768w\" sizes=\"(max-width: 960px) 100vw, 960px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-how-to-install-node-js-from-nodesource\">How to Install Node.js from NodeSource<\/h3><p>To install a specific version of Node.js, use a third-party <a href=\"https:\/\/help.ubuntu.com\/stable\/ubuntu-help\/addremove-ppa.html.en\" target=\"_blank\" rel=\"noopener\">personal package archive<\/a> (PPA) repository like <strong>NodeSource<\/strong>. It offers more package variations and frequent updates than the official Ubuntu repo to ensure you get the latest release.<\/p><p>The setup process is similar to using the Ubuntu repository, but you must add the PPA source before installing. Here are the steps:<\/p><ol class=\"wp-block-list\">\n<li>Install the <a href=\"\/uk\/tutorials\/curl-command-with-examples-linux\/\">cURL utility<\/a>, which we will use to download the PPA repository. Skip this step if you have it installed:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt install curl<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Run the following to download the Node.js package. Replace<strong> 22.x <\/strong>with your desired version number:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo curl -fsSL https:\/\/deb.nodesource.com\/setup_22.x | sudo -E bash -<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Update your system repository to synchronize the package:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt update<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Install Node.js and NPM by running these commands subsequently:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt install nodejs<br><br>sudo apt install npm<\/pre><ol start=\"5\" class=\"wp-block-list\">\n<li>Verify that Node.js and NPM are successfully installed by querying their version numbers with these commands:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo nodejs -v<br><br>sudo npm -v<\/pre><p>To learn more about the supported versions and Node.js release calendar, check out the <a href=\"https:\/\/github.com\/nodesource\/distributions\" target=\"_blank\" rel=\"noopener\">NodeSource GitHub page<\/a>.<\/p><h3 class=\"wp-block-heading\" id=\"h-how-to-install-node-js-using-node-version-manager\">How to Install Node.js using Node Version Manager<\/h3><p>In some cases, you might need to switch between different Node.js installations based on your project requirements. Since the previous steps configured a packaged version from a repository, you don&rsquo;t have such flexibility.<\/p><p>The best Node.js installation method for this use case is with the <strong>Node Version Manager (NVM)<\/strong>. This <a href=\"\/uk\/tutorials\/bash-script-example\">bash script<\/a> lets you easily configure and manage multiple versions of the JavaScript runtime.<\/p><p>To set up Node.js using this method, download the NVM installation script using the following cURL command:<\/p><pre class=\"wp-block-preformatted\">sudo curl -o- https:\/\/raw.githubusercontent.com\/nvm-sh\/nvm\/v0.39.7\/install.sh | bash&nbsp;<\/pre><p>Replace <strong>0.39.7 <\/strong>with another value if you want to download a different installation script version. Check the <a href=\"https:\/\/github.com\/nvm-sh\/nvm?tab=readme-ov-file\" target=\"_blank\" rel=\"noopener\">NVM GitHub repository<\/a> to learn more about the available options.<\/p><p>Now, allow the NVM script to run on your current user&rsquo;s bash shell:<\/p><pre class=\"wp-block-preformatted\">source ~\/.profile<\/pre><p>Check whether you install NVM correctly by querying its version number:<\/p><pre class=\"wp-block-preformatted\">nvm -&ndash;version<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69dfa62bd78a9\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"850\" height=\"47\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/command-line-interface-returns-nvm-version-number.png\" alt=\"Command-line interface returns NVM version number\" class=\"wp-image-109980\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/command-line-interface-returns-nvm-version-number.png 850w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/command-line-interface-returns-nvm-version-number-300x17.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/command-line-interface-returns-nvm-version-number-150x8.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/command-line-interface-returns-nvm-version-number-768x42.png 768w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>After installing NVM, follow these steps to set up Node.js:<\/p><ol class=\"wp-block-list\">\n<li>List all the available Node.js versions in NVM using this command. Since the output will be rather long, press <strong>Ctrl + C<\/strong> to terminate the process once you feel the list is sufficient:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">nvm ls-remote<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Run the following command to install your desired Node.js version using the NVM script. Replace the version number with the actual value:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">nvm install 22.1.0<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Query the Node.js version number to verify its installation:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">node -v<\/pre><p>If you want to install more versions of Node.js, simply rerun the <strong>nvm install<\/strong> command. To switch between them, use the following:<\/p><pre class=\"wp-block-preformatted\">nvm use 22.0.0<\/pre><p>Replace the number with the Node.js release you want to use. The <strong>nvm <\/strong>command also lets you manage multiple installations of the runtime environment. For example, run the following to list all the installed versions in your Ubuntu system:<\/p><pre class=\"wp-block-preformatted\">nvm ls<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69dfa62bd8907\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"975\" height=\"399\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/nvm-lists-all-installed-nodejs-versions.png\" alt=\"NVM lists all installed Node.js versions\" class=\"wp-image-109981\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/nvm-lists-all-installed-nodejs-versions.png 975w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/nvm-lists-all-installed-nodejs-versions-300x123.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/nvm-lists-all-installed-nodejs-versions-150x61.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/05\/nvm-lists-all-installed-nodejs-versions-768x314.png 768w\" sizes=\"(max-width: 975px) 100vw, 975px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>The <strong>arrow<\/strong> symbol indicates your currently active Node.js installation. Meanwhile, the <strong>default <\/strong>version shows the one that will automatically apply to a new shell. You can change it by entering:<\/p><pre class=\"wp-block-preformatted\">sudo nvm alias default 22.15.0<\/pre><p>Since keeping too many Node.js installed in your VPS might cause performance issues, we recommend removing the unused ones using the following command:<\/p><pre class=\"wp-block-preformatted\">nvm uninstall 22.15<\/pre><p>Note that NVM will remove the newer version if you have two major releases installed, like <strong>22.15.0<\/strong> and <strong>22.15.1<\/strong>. If you want to uninstall both, run the command twice.<\/p><p><div><p class=\"important\"><strong>Important!<\/strong> NVM can&rsquo;t uninstall a currently active version. Before removing an installation, ensure to switch to another release. <\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-node-js-on-ubuntu-best-practices\">Node.js on Ubuntu Best Practices<\/h2><p>As an integral part of your JavaScript application&rsquo;s functionality, maintain Node.js properly after installing it. In this section, we will explain several best practices when using the runtime environment.<\/p><h3 class=\"wp-block-heading\" id=\"h-utilize-package-json\">Utilize Package.json<\/h3><p>Node.js and NPM let users create <strong>package.json<\/strong> in their project directory to define the application&rsquo;s dependency list, configuration, and metadata. It helps simplify management tasks since you will only use a single file.<\/p><p>To create it, navigate to your project&rsquo;s folder using the <strong>cd<\/strong> command. Then, run the following:<\/p><pre class=\"wp-block-preformatted\">npm init<\/pre><p>Open the new file using the nano text editor to add the dependency list. Here&rsquo;s the command:<\/p><pre class=\"wp-block-preformatted\">sudo nano package.json<\/pre><p>You can also specify custom scripts that automate various tasks, like starting the Node.js server or running the test commands. Once finished, save the changes by pressing <strong>Ctrl + X<\/strong> &rarr; <strong>Y<\/strong> &rarr; <strong>Enter<\/strong>.<\/p><p>If you are unsure how to write the JSON configuration, use Kodee to generate it. For example, ask &ldquo;Generate a package.json configuration for a Node.js application that uses the latest version of Express, Mongoose, body-parser, and dotenv as its dependencies.&rdquo;<\/p><figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/10\/kodee-package-json.png\"><img decoding=\"async\" width=\"1024\" height=\"549\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/10\/kodee-package-json-1024x549.png\" alt=\"Kodee generates JSON configuration specifying project dependencies\" class=\"wp-image-117032\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/10\/kodee-package-json-1024x549.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/10\/kodee-package-json-300x161.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/10\/kodee-package-json-150x80.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/10\/kodee-package-json-768x412.png 768w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/10\/kodee-package-json.png 1101w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>Then, simply copy and paste the configuration into your VPS. Remember that since AI updates its information slowly, double-check the version to ensure you have the latest release.<\/p><p>After specifying the dependencies, you can easily install them simultaneously using a single command:<\/p><pre class=\"wp-block-preformatted\">npm install<\/pre><p>To run a script, simply specify its name after<strong> npm<\/strong>. For instance, the following will execute the <strong>test <\/strong>script:<\/p><pre class=\"wp-block-preformatted\">npm test<\/pre><h3 class=\"wp-block-heading\" id=\"h-update-node-js-regularly\">Update Node.js Regularly<\/h3><p>Keep Node.js and NPM up to date to maintain optimal security and functionality. While you can use the APT package manager, it might not offer the newest version.<\/p><p>Instead, use NPM to update both software. To update the Node package manager, run the following command:<\/p><pre class=\"wp-block-preformatted\">sudo npm install -g rpm@latest<\/pre><p>To update the Node.js runtime, you need to install the <strong>n <\/strong>version management tool first using this command:<\/p><pre class=\"wp-block-preformatted\">sudo npm install -g n&nbsp;<\/pre><p>Then, download the latest Node.js version from NPM by entering the following:<\/p><pre class=\"wp-block-preformatted\">sudo n latest<\/pre><p>Query both software versions to verify the installation. We recommend regularly checking the <a href=\"https:\/\/nodejs.org\/en\/about\/previous-releases\" target=\"_blank\" rel=\"noopener\">Node.js release note page<\/a> to get notified about a new version as soon as possible. Also, use <strong>long-term support<\/strong> (LTS) releases since they are more stable and have longer update guarantees.<\/p><p>In addition, periodically check for outdated packages in your <strong>package.json <\/strong>file. You can do so using this <strong>npm<\/strong> command:<\/p><pre class=\"wp-block-preformatted\">npm outdated<\/pre><p>Then, install all the available updates simultaneously using this command:<\/p><pre class=\"wp-block-preformatted\">npm update<\/pre><p><div><p class=\"important\"><strong>Important!<\/strong> Before installing a new version of Node.js, ensure your application supports it to avoid incompatibility issues.<\/p><\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-secure-node-js\">Secure Node.js<\/h3><p>Securing Node.js and its components is crucial since this runtime environment is susceptible to various injection attacks like cross-site scripting (XSS). In addition to updating, there are additional measures to consider.<\/p><p>If you use the <strong>package.json<\/strong> file, run the following command to list all security vulnerabilities in your application&rsquo;s dependencies:<\/p><pre class=\"wp-block-preformatted\">npm audit<\/pre><p>You can then take necessary precautions to safeguard your project based on these insights. Also, run the following to remove unnecessary packages that are not dependencies, which can present security risks:<\/p><pre class=\"wp-block-preformatted\">npm prune<\/pre><p>Moreover, conduct regular log audits to catch unauthorized events, which can indicate security incidents. Since Node.js doesn&rsquo;t offer such a feature by default, configure a third-party tool like <a href=\"https:\/\/github.com\/winstonjs\/winston\" target=\"_blank\" rel=\"noopener\">Winston<\/a>.<\/p><p>In addition, implement other basic <a href=\"\/uk\/tutorials\/vps-security\">VPS security measures<\/a> like installing a secure sockets layer (SSL) certificate, setting up <strong>Fail2Ban<\/strong>, and enforcing firewall rules for your network interfaces.<\/p><p>We also recommend checking the <a href=\"https:\/\/nodejs.org\/en\/learn\/getting-started\/security-best-practices\" target=\"_blank\" rel=\"noopener\">Node.js security best practices<\/a> documentation to learn more about the software&rsquo;s current threat models and their recommended solutions.<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Installing the Node.js runtime environment is crucial for your JavaScript application&rsquo;s functionality. Hostinger users can easily do so by choosing the <strong>Ubuntu 22.04 with Node.js<\/strong> template in <strong>hPanel<\/strong>.<\/p><p>Alternatively, users who prefer another version of Node.js can install it manually using commands. After connecting to the VPS via SSH, configure it from the Ubuntu repository using the APT package manager.<\/p><p>If you want to select a specific version, download the NodeSource PPA and configure Node.js from the repo. Should you need to install multiple Node.js versions, use the NVM method. After downloading the script, run the <strong>nvm install<\/strong> command to configure the runtime environment.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-install-node-js-on-ubuntu-faq\">How to Install Node.js on Ubuntu FAQ<\/h2><p>To deepen your understanding, this section will answer several questions about installing Node.js on an Ubuntu machine.<\/p><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1715852340990\"><h3 class=\"schema-faq-question\">What Version of Node.js Will Be Installed by Default on Ubuntu?<\/h3> <p class=\"schema-faq-answer\">It depends on the Ubuntu version and the developer update cycle. For example, currently installing Node.js from the <strong>Ubuntu 22.04<\/strong> default repository will configure version <strong>12.22.9<\/strong>.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1715852347067\"><h3 class=\"schema-faq-question\">How Do I Uninstall Node.js From My Ubuntu System?<\/h3> <p class=\"schema-faq-answer\">Use the apt remove or apt purge command if you want to delete the configuration file as well. If you use nvm, run<strong> nvm uninstall <\/strong>followed by the version number.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1715852352063\"><h3 class=\"schema-faq-question\">In Which Directory Is Node.js Installed on Ubuntu?<\/h3> <p class=\"schema-faq-answer\">It depends on the installation method. If you configure the runtime via the NodeSource repository, Node.js is under<strong> \/usr\/local\/bin\/node<\/strong>. However, installing it via APT will put it under <strong>\/usr\/bin\/nod<\/strong>e. To check the location, you can run the <strong>which node<\/strong> command.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Node.js is a runtime environment that provides software components and interfaces to allow JavaScript code to run properly. Setting it up in the host server is essential if your web application uses the programming language. In this tutorial, you will learn how to install Node.js on Ubuntu virtual private server (VPS). We will cover two [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/uk\/tutorials\/how-to-install-nodejs-ubuntu\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":337,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Install Node.js on Ubuntu","rank_math_description":"In this article, we'll provide 4 easy methods to install Node.js on Ubuntu using the pre-made Hostinger VPS template, using APT and NPM + more.","rank_math_focus_keyword":"ubuntu install nodejs","footnotes":""},"categories":[22640],"tags":[],"class_list":["post-15432","post","type-post","status-publish","format-standard","hentry","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-install-nodejs-ubuntu","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/instalar-node-js-ubuntu","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/comment-installer-node-js-sur-ubuntu","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/instalar-node-js-ubuntu","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/install-node-js-ubuntu","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-install-nodejs-ubuntu","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-install-nodejs-ubuntu","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-install-nodejs-ubuntu","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/que-son-hooks-wordpress-18","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/que-son-hooks-wordpress-18","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/instalar-node-js-ubuntu","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/instalar-node-js-ubuntu","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-install-nodejs-ubuntu","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-install-nodejs-ubuntu","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-install-nodejs-ubuntu","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-install-nodejs-ubuntu","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/15432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/users\/337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/comments?post=15432"}],"version-history":[{"count":69,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/15432\/revisions"}],"predecessor-version":[{"id":129334,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/15432\/revisions\/129334"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/media?parent=15432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/categories?post=15432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/tags?post=15432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}