{"id":1925,"date":"2022-05-23T10:09:52","date_gmt":"2022-05-23T08:09:52","guid":{"rendered":"https:\/\/nguenkam.com\/blog\/?p=1925"},"modified":"2022-05-23T10:12:42","modified_gmt":"2022-05-23T08:12:42","slug":"how-to-install-node-js-on-debian-10","status":"publish","type":"post","link":"https:\/\/nguenkam.com\/blog\/index.php\/2022\/05\/23\/how-to-install-node-js-on-debian-10\/","title":{"rendered":"How To install &#038; update Node.js on Debian 10"},"content":{"rendered":"\n<p><a href=\"https:\/\/nodejs.org\/\">Node.js<\/a>&nbsp;is a JavaScript runtime for server-side programming. It allows developers to create scalable backend functionality using JavaScript, a language many are already familiar with from browser-based web development.<\/p>\n\n\n\n<h4>Installing Node.js with Apt from the Default Repositories<\/h4>\n\n\n\n<p>Debian contains a version of Node.js in its default repositories that can be used to provide a consistent experience across multiple systems. At the time of writing, the version in the repositories is 10.24.0. This will not be the latest version, but it should be stable and sufficient for quick experimentation with the language.<\/p>\n\n\n\n<p><span class=\"has-inline-color has-vivid-red-color\"><strong>Warning:<\/strong>&nbsp;<\/span><em>The version of Node.js included with Debian 10, version 10.24.0, is unsupported and unmaintained. You should not use this version in production, and should refer to one of the other sections in this tutorial to install a more recent version of Node.<\/em><\/p>\n\n\n\n<p>To get Node.js from the default Debian software repository, you can use the&nbsp;<code>apt<\/code>&nbsp;package manager. First, refresh your local package index:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update<\/code><\/pre>\n\n\n\n<p>Then install the Node.js package:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install nodejs<\/code><\/pre>\n\n\n\n<p>To verify that the installation was successful, run the&nbsp;<code>node<\/code>&nbsp;command with the&nbsp;<code>-v<\/code>&nbsp;flag to get the version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node -v<\/code><\/pre>\n\n\n\n<p>If the package in the repositories suits your needs, this is all you need to do to get set up with Node.js. In most cases, you\u2019ll also want to also install&nbsp;<code>npm<\/code>, the Node.js package manager. You can do this by installing the&nbsp;<code>npm<\/code>&nbsp;package with&nbsp;<code>apt<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install npm<\/code><\/pre>\n\n\n\n<p>This will allow you to install modules and packages to use with Node.js.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>PS: <\/strong><em>The next section will show how to use an alternate repository to install different versions of Node.js.<\/em><\/p>\n\n\n\n<h4>Installing Node.js with Apt Using a NodeSource PPA<\/h4>\n\n\n\n<p>To work with a more recent version of Node.js, you can install from a&nbsp;<em>PPA<\/em>&nbsp;(personal package archive) maintained by&nbsp;<a href=\"https:\/\/nodesource.com\/\">NodeSource<\/a>.&nbsp;<\/p>\n\n\n\n<p>This is an alternate repository that still works with&nbsp;<code>apt<\/code>, and will have more up-to-date versions of Node.js than the official Debian repositories. NodeSource has PPAs available for multiple Node versions. Refer to the&nbsp;<a href=\"https:\/\/github.com\/nodesource\/distributions\/blob\/master\/README.md\">NodeSource documentation<\/a>&nbsp;for more information on the available versions.<\/p>\n\n\n\n<p>From your home directory, use&nbsp;<code><em><strong>curl<\/strong><\/em><\/code>&nbsp;to retrieve the installation script for your preferred Node.js version. If you do not have&nbsp;<code>curl<\/code>&nbsp;installed, you can install it before proceeding to the next step with this command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install curl<\/code><\/pre>\n\n\n\n<p>With&nbsp;<code>curl<\/code>&nbsp;installed, you can begin your Node.js installation. This example installs version&nbsp;<code><mark>16.x<\/mark><\/code>. You can replace&nbsp;<code><mark>16.x<\/mark><\/code>&nbsp;with your preferred version.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -fsSL https:\/\/deb.nodesource.com\/setup_16.x | sudo -E bash -\nsudo apt install nodejs<\/code><\/pre>\n\n\n\n<p>You don\u2019t need to install a separate package for&nbsp;<code>npm<\/code>&nbsp;in this case, as it is included in the&nbsp;<code>nodejs<\/code>&nbsp;package.<\/p>\n\n\n\n<p>Verify the installation by running&nbsp;<code>node<\/code>&nbsp;with the&nbsp;<code>-v<\/code>&nbsp;version option:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node -v<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4>Update Node.js with NPM<\/h4>\n\n\n\n<p>If you want to upgrade Node.js from the command line, use the&nbsp;<strong>n model<\/strong>&nbsp;within the&nbsp;<strong><code>npm<\/code><\/strong>&nbsp;command. The&nbsp;<strong><code>n<\/code><\/strong>&nbsp;feature allows you to interact with different Node.js versions.<\/p>\n\n\n\n<p>1. Before updating the Node.js release, check which version you are currently using with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node -v<\/code><\/pre>\n\n\n\n<p>2. Next, clear npm cache with the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm cache clean -f<\/code><\/pre>\n\n\n\n<p>3. Install&nbsp;<strong>n<\/strong>&nbsp;globally:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install -g n<\/code><\/pre>\n\n\n\n<p>4. Now that you have n installed, you can use the module to install the latest stable release of Node.js:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo n stable<\/code><\/pre>\n\n\n\n<p>Alternatively, you can install the Node.js release with the latest features:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo n latest<\/code><\/pre>\n\n\n\n<p>Or, install a specific version number with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>n &#91;version.number]<\/code><\/pre>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h5>Reference:<\/h5>\n\n\n\n<p><a href=\"https:\/\/www.digitalocean.com\/\">https:\/\/www.digitalocean.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Node.js&nbsp;is a JavaScript runtime for server-side programming. It allows developers to create scalable backend functionality using JavaScript, a language many are already familiar with from browser-based web development. Installing Node.js with Apt from the Default Repositories Debian contains a version of Node.js in its default repositories that can be used to provide a consistent experience [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1928,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[145],"tags":[194,547,171,548],"_links":{"self":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1925"}],"collection":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1925"}],"version-history":[{"count":4,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1925\/revisions"}],"predecessor-version":[{"id":1930,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1925\/revisions\/1930"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/1928"}],"wp:attachment":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}