{"id":1507,"date":"2021-01-17T17:07:52","date_gmt":"2021-01-17T17:07:52","guid":{"rendered":"https:\/\/linuxbuz.com\/?p=1507"},"modified":"2021-07-11T12:34:52","modified_gmt":"2021-07-11T12:34:52","slug":"install-node-js-ubuntu","status":"publish","type":"post","link":"https:\/\/linuxbuz.com\/linuxhowto\/install-node-js-ubuntu","title":{"rendered":"How to Install Node.js and NPM on Ubuntu 20.04"},"content":{"rendered":"\n<p style=\"text-align: justify;\"><strong>Node.js<\/strong> is a JavaScript runtime environment used to run JavaScript code on the server-side. It is a cross-platform designed to build fast and scalable back-end applications.<\/p>\n<p style=\"text-align: justify;\"><strong>NPM<\/strong> also know as a &#8220;<strong>Node Package Manager<\/strong>&#8221; is an online repository for developing and sharing JavaScript code. Generally, it is used for automated dependency and package management. You can specify all your projects dependencies in your package.json file then just run npm install command to install all dependencies.<\/p>\n<p>In this tutorial, you will learn &#8211;<\/p>\n<ul>\n<li><a href=\"#1\">Install Node.js and NPM from Ubuntu Repository<\/a><\/li>\n<li><a href=\"#2\">Install Node.js and NPM from the NodeSource Repository<\/a><\/li>\n<li><a href=\"#3\">Install Node.js and NPM using NVM<\/a><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span><span style=\"color: #3c314d;\">Prerequisites<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>A server running Ubuntu 20.04.<\/li>\n<li>A root password is configured on your server.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Install_Nodejs_and_NPM_from_Ubuntu_Repository\"><\/span><span style=\"color: #3c314d;\">Install Node.js and NPM from Ubuntu Repository<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">At the time of writing this article, the latest Node.js version available in the Ubuntu default repository is <strong>10.x<\/strong>. This is the simple and easiest method to install Node.js on Ubuntu.<\/p>\n<p>First, update the package cache with the following command:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">apt-get update -y<\/pre>\n<p>Next, install the Node.js and NPM using the following command:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">apt-get install nodejs npm -y<\/pre>\n<p>Once the installation if complete, verify the Node.js version with the following command:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">node --version<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">v10.19.0\n<\/pre>\n<p>You can also verify the NPM version with the following command:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">npm --version<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">6.14.4<\/pre>\n<p>If you want to uninstall Node.js and NPM from your system, run the following commands:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">apt-get remove nodejs npm --purge\napt-get autoremove\napt-get clean<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Install_Nodejs_and_NPM_from_the_NodeSource_Repository\"><\/span><span style=\"color: #3c314d;\"><a id=\"2\"><\/a>Install Node.js and NPM from the NodeSource Repository<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><strong>NodeSource<\/strong> repository allows you to install multiple version of Node.js in your system. At the time of writing this article, <strong>NodeSource<\/strong> supports Node.js v15.x, v14.x, v13.x, v12.x, and v10.x. This method is very useful if your application requires a specific version of <strong>Node.js<\/strong>.<\/p>\n<p>Here, we will install <strong>Node.js<\/strong> version <strong>14.x<\/strong> from the <strong>NodeSource<\/strong> repository.<\/p>\n<p>First, install the curl command-line tool with the following command:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">apt-get install curl -y<\/pre>\n<p>Next, download and run the <strong>NodeSource<\/strong> installation script using the following command:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">curl -sL https:\/\/deb.nodesource.com\/setup_14.x | bash -<\/pre>\n<p style=\"text-align: justify;\">This command will add <strong>NodeSource<\/strong> signing key, install all dependencies and add Node.js repository to the APT source file.<\/p>\n<p><strong>Note:<\/strong> Just replace <strong>14.x<\/strong> with <strong>15.x<\/strong>, <strong>12.x<\/strong> or <strong>10.x<\/strong> if you want to install another Node.js version.<\/p>\n<p>Once the repository is added, install the <strong>Node.js<\/strong> and <strong>NPM<\/strong> with the following command:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">apt-get install nodejs -y<\/pre>\n<p>Once installed, verify the Node.js version using the following command:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">node --version<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">v14.15.4<\/pre>\n<p>To verify the <strong>NPM<\/strong> version, run the following command:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">npm --version<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">6.14.10<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Install_Nodejs_and_NPM_using_NVM\"><\/span><span style=\"color: #3c314d;\"><a id=\"3\"><\/a>Install Node.js and NPM using NVM<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><strong>NVM<\/strong> stands for &#8220;<strong>Node Version Manager<\/strong>&#8221; is a tool used to download and install multiple <strong>Node.js<\/strong> versions in your system. It helps you <strong>manage<\/strong> and <strong>switch<\/strong> between different <strong>Node<\/strong> versions with ease.<\/p>\n<p>First, go to the <strong>NVM Git Repository<\/strong> and download the latest version of <strong>NVM<\/strong> script.<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">curl -o- https:\/\/raw.githubusercontent.com\/nvm-sh\/nvm\/v0.37.2\/install.sh | bash -<\/pre>\n<p style=\"text-align: justify;\">This script will clone the nvm repository to<strong> ~\/.nvm<\/strong>, and attempts to add the source lines from the snippet below to the correct profile file:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n100 13527  100 13527    0     0  69369      0 --:--:-- --:--:-- --:--:-- 69015\n=&gt; Downloading nvm as script to '\/root\/.nvm'\n\n=&gt; Appending nvm source string to \/root\/.bashrc\n=&gt; Appending bash_completion source string to \/root\/.bashrc\n=&gt; Close and reopen your terminal to start using nvm or run the following to use it now:\n\nexport NVM_DIR=\"$HOME\/.nvm\"\n[ -s \"$NVM_DIR\/nvm.sh\" ] &amp;&amp; \\. \"$NVM_DIR\/nvm.sh\"  # This loads nvm\n[ -s \"$NVM_DIR\/bash_completion\" ] &amp;&amp; \\. \"$NVM_DIR\/bash_completion\"  # This loads nvm bash_completion\n<\/pre>\n<p>Next, close and reopen the terminal or run the following command to <strong>activate<\/strong> the profile.<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">export NVM_DIR=\"$HOME\/.nvm\"\n[ -s \"$NVM_DIR\/nvm.sh\" ] &amp;&amp; \\. \"$NVM_DIR\/nvm.sh\"\n[ -s \"$NVM_DIR\/bash_completion\" ] &amp;&amp; \\. \"$NVM_DIR\/bash_completion\"\n<\/pre>\n<p>Next, verify the <strong>NVM<\/strong> version with the following command:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">nvm --version<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">0.37.2<\/pre>\n<p>Next, print a list of all available <strong>Node.js<\/strong> version using the following command:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">nvm list-remote<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">       v14.15.0   (LTS: Fermium)\n       v14.15.1   (LTS: Fermium)\n       v14.15.2   (LTS: Fermium)\n       v14.15.3   (LTS: Fermium)\n-&gt;     v14.15.4   (Latest LTS: Fermium)\n        v15.0.0\n        v15.0.1\n        v15.1.0\n        v15.2.0\n        v15.2.1\n        v15.3.0\n        v15.4.0\n        v15.5.0\n        v15.5.1\n        v15.6.0\n<\/pre>\n<p>If you want to install the latest <strong>stable<\/strong> <strong>Node.js<\/strong> version, run the command below:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">nvm install --lts<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">Installing latest LTS version.\nDownloading and installing node v14.15.4...\nDownloading https:\/\/nodejs.org\/dist\/v14.15.4\/node-v14.15.4-linux-x64.tar.xz...\n######################################################################################################################################## 100.0%\nComputing checksum with sha256sum\nChecksums matched!\nNow using node v14.15.4 (npm v6.14.10)\nCreating default alias: default -&gt; lts\/* (-&gt; v14.15.4)\n<\/pre>\n<p>If you want to install <strong>Node.js<\/strong> latest version <strong>v15.6.0<\/strong>, run the command below:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">nvm install v15.6.0<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">Downloading and installing node v15.6.0...\nDownloading https:\/\/nodejs.org\/dist\/v15.6.0\/node-v15.6.0-linux-x64.tar.xz...\n######################################################################################################################################## 100.0%\nComputing checksum with sha256sum\nChecksums matched!\nNow using node v15.6.0 (npm v7.4.0)\n<\/pre>\n<p>To list all installed <strong>Node.js versions<\/strong>, run the following command:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">nvm ls\n<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">       v14.15.4\n-&gt;      v15.6.0\n<\/pre>\n<p>To check the <strong>active<\/strong> Node.js version, run the command below:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">node --version<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">v15.6.0<\/pre>\n<p>Now, <strong>change<\/strong> the default Node.js version to <strong>v14.15.4<\/strong>, run the command below:<\/p>\n<pre class=\"brush: bash; light: false; title: ; toolbar: true; notranslate\" title=\"\">nvm use v14.15.4<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><span style=\"color: #3c314d;\">Conclusion<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In the above post, you learned how to install <strong>Node.js<\/strong> using three different ways. You can now choose your desired way to install <strong>Node.js<\/strong> on Ubuntu 20.04.<\/p>\n<p>If you want to manage your application dependencies. I would recommend installing Yarn to manage the dependency.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Node.js is a JavaScript runtime environment used to run JavaScript code on the server-side. It is a cross-platform designed to build fast and scalable back-end applications. NPM also know as &hellip; <\/p>\n","protected":false},"author":1,"featured_media":1511,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"two_page_speed":[],"footnotes":""},"categories":[12],"tags":[],"class_list":["post-1507","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linuxhowto"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/linuxbuz.com\/wp-json\/wp\/v2\/posts\/1507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxbuz.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxbuz.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxbuz.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxbuz.com\/wp-json\/wp\/v2\/comments?post=1507"}],"version-history":[{"count":0,"href":"https:\/\/linuxbuz.com\/wp-json\/wp\/v2\/posts\/1507\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxbuz.com\/wp-json\/wp\/v2\/media\/1511"}],"wp:attachment":[{"href":"https:\/\/linuxbuz.com\/wp-json\/wp\/v2\/media?parent=1507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxbuz.com\/wp-json\/wp\/v2\/categories?post=1507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxbuz.com\/wp-json\/wp\/v2\/tags?post=1507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}