{"id":39343,"date":"2024-08-02T02:41:21","date_gmt":"2024-08-02T08:11:21","guid":{"rendered":"https:\/\/www.solutionanalysts.com\/blog\/?p=39343"},"modified":"2024-12-16T03:55:20","modified_gmt":"2024-12-16T09:25:20","slug":"how-to-install-node-js-on-ubuntu","status":"publish","type":"post","link":"https:\/\/www.solutionanalysts.com\/blog\/how-to-install-node-js-on-ubuntu\/","title":{"rendered":"How to Install Node.js on Ubuntu"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">\u00a0Installing Node.js on Ubuntu is a simple procedure that requires only a few steps. Node.js is a popular JavaScript runtime based on Chrome&#8217;s V8 JavaScript engine that is commonly used for developing server-side applications. This tutorial will help you through the installation steps. Let&#8217;s have a look at the steps for install Node.js on Ubuntu.\u00a0<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span><b>Prerequisites<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Before you start, make sure you have the following:\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; A version of Ubuntu, preferred version v18.04 or later<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; A user account with sudo privileges.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Basic Knowledge of Linux terminal commands.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Internet access.\u00a0<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Step_1_Update_Your_System\"><\/span><b>Step 1: Update Your System\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Many developers choose <a href=\"https:\/\/www.solutionanalysts.com\/blog\/choose-nodejs-for-web-application-development-project\/\">Node.js for web application development project<\/a>, to do that following process needs to be followed. Before installing any new software, it&#8217;s always a good practice to update your system&#8217;s package index to ensure you have the latest versions of packages and their dependencies.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Open your terminal and run:\u00a0<\/span><\/p>\n<div class=\"cards\">\n<div class=\"card-contents\"><span style=\"font-weight: 400;\">sudo apt update<\/span><span style=\"font-weight: 400;\">sudo apt upgrade -y\u00a0<\/span><\/p>\n<\/div>\n<\/div>\n<h3><span class=\"ez-toc-section\" id=\"Step_2_Install_Nodejs_on_Ubuntu\"><\/span><b>Step 2: Install Node.js on Ubuntu<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">We&#8217;ll go over the two most prevalent methods: utilizing the NodeSource repository and NVM (Node Version Manager).\u00a0<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Method_1_Using_the_NodeSource_Repository\"><\/span><b>Method 1: Using the NodeSource Repository\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li aria-level=\"1\">\n<h3><span class=\"ez-toc-section\" id=\"Add_NodeSource_Repository\"><\/span><b>Add NodeSource Repository\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">The easiest way to install Node.js on Ubuntu is using the official Ubuntu repository. To add it, run the following command:<\/span><\/p>\n<div class=\"cards\">\n<div class=\"card-contents\"><span style=\"font-weight: 400;\">curl -fsSL https:\/\/deb.nodesource.com\/setup_20.x | sudo -E bash &#8211;\u00a0<\/span><\/div>\n<\/div>\n<p><span style=\"font-weight: 400;\">This command fetches and executes the NodeSource installation script.\u00a0<\/span><\/p>\n<ul>\n<li aria-level=\"1\">\n<h3><span class=\"ez-toc-section\" id=\"Install_Nodejs_on_Ubuntu\"><\/span><b>Install Node.js on Ubuntu<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">After adding the repository, install Node.js using:\u00a0<\/span><\/p>\n<div class=\"cards\">\n<div class=\"card-contents\"><span style=\"font-weight: 400;\">sudo apt install -y nodejs\u00a0<\/span><\/div>\n<\/div>\n<p><span style=\"font-weight: 400;\">This command installs both `node` and `npm` (Node Package Manager).\u00a0<\/span><\/p>\n<ul>\n<li aria-level=\"1\">\n<h3><span class=\"ez-toc-section\" id=\"Verify_Installation\"><\/span><b>Verify Installation\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Verify the installation by checking the versions:\u00a0<\/span><\/p>\n<div class=\"cards\">\n<div class=\"card-contents\"><span style=\"font-weight: 400;\">node -v<br \/>\n<\/span><\/div>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-39346\" src=\"https:\/\/www.solutionanalysts.com\/blog\/wp-content\/uploads\/2024\/08\/node-v.png\" alt=\"node -v\" width=\"590\" height=\"78\" \/><\/p>\n<div class=\"cards\">\n<div class=\"card-contents\"><span style=\"font-weight: 400;\">npm -v\u00a0<\/span><\/div>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-39347\" src=\"https:\/\/www.solutionanalysts.com\/blog\/wp-content\/uploads\/2024\/08\/nvm-v.png\" alt=\"nvm -v\" width=\"680\" height=\"70\" \/><\/p>\n<p><span style=\"font-weight: 400;\">You should see output similar to:\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V20.x.x<\/span><\/p>\n<p><span style=\"font-weight: 400;\">9.x.x\u00a0<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Method_2_Using_NVM_Node_Version_Manager\"><\/span><b>Method 2: Using NVM (Node Version Manager)\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li aria-level=\"1\">\n<h3><span class=\"ez-toc-section\" id=\"Install_NVM\"><\/span><b>Install NVM\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">NVM is a script-based solution that lets you manage various active Node.js versions. This is very important when you need to move between Node.js versions.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Download and install NVM using the following command:\u00a0<\/span><\/p>\n<div class=\"cards\">\n<div class=\"card-contents\"><span style=\"font-weight: 400;\">curl -o- https:\/\/raw.githubusercontent.com\/nvm-sh\/nvm\/v0.38.0\/install.sh | bash\u00a0<\/span><\/div>\n<\/div>\n<p><span style=\"font-weight: 400;\">To start using NVM, you need to source your profile:\u00a0<\/span><\/p>\n<div class=\"cards\">\n<div class=\"card-contents\"><span style=\"font-weight: 400;\">source ~\/.bashrc\u00a0<\/span><\/div>\n<\/div>\n<ul>\n<li aria-level=\"1\">\n<h3><span class=\"ez-toc-section\" id=\"Install_Nodejs_on_Ubuntu_with_NVM\"><\/span><b>Install Node.js on Ubuntu with NVM\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">With NVM installed, you can install the latest LTS (Long Term Support) version of Node.js:\u00a0<\/span><\/p>\n<div class=\"cards\">\n<div class=\"card-contents\"><span style=\"font-weight: 400;\">nvm install &#8211;lts\u00a0<\/span><\/div>\n<\/div>\n<ul>\n<li aria-level=\"1\">\n<h3><span class=\"ez-toc-section\" id=\"Verify_Installation-2\"><\/span><b>Verify Installation<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Check the installed versions of Node.js and npm:\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">node -v<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-39346\" src=\"https:\/\/www.solutionanalysts.com\/blog\/wp-content\/uploads\/2024\/08\/node-v.png\" alt=\"node -v\" width=\"590\" height=\"78\" \/><br \/>\n<\/span><span style=\"font-weight: 400;\">npm -v<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-39347\" src=\"https:\/\/www.solutionanalysts.com\/blog\/wp-content\/uploads\/2024\/08\/nvm-v.png\" alt=\"nvm -v\" width=\"680\" height=\"70\" \/><\/span><\/p>\n<p><span style=\"font-weight: 400;\">The output should reflect the versions you installed using NVM.\u00a0<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_3_Manage_Nodejs_Versions_Optional\"><\/span><b>Step 3: Manage Node.js Versions (Optional)\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">If you installed Node.js using NVM, you can easily switch between different versions:\u00a0<\/span><\/p>\n<ul>\n<li aria-level=\"1\">\n<h3><span class=\"ez-toc-section\" id=\"List_Installed_Versions\"><\/span><b>List Installed Versions\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Command:nvm ls\u00a0<\/span><\/p>\n<ul>\n<li aria-level=\"1\">\n<h3><span class=\"ez-toc-section\" id=\"Use_a_Specific_Version\"><\/span><b>Use a Specific Version\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">nvm use 14.17.0\u00a0<\/span><\/p>\n<ul>\n<li aria-level=\"1\">\n<h3><span class=\"ez-toc-section\" id=\"Set_Default_Version\"><\/span><b>Set Default Version\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">nvm alias default 20.19.1\u00a0<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><b>Conclusion\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Congratulations! You have successfully installed Node.js on your Ubuntu machine. Whether you utilize the NodeSource repository or NVM, you now have an effective tool for developing scalable network applications.<\/span><\/p>\n<h2><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"Additional_Tips\"><\/span><b>Additional Tips<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">To update Node.js run the following command\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">sudo apt update &amp;&amp; sudo apt install nodejs<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">To uninstall Node.js, run the following command<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">sudo apt purge nodejs<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">To install specific version of Node.js using NVM, run the following command<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">nvm install &lt;version&gt;.\u00a0<\/span>\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-39349\" src=\"https:\/\/www.solutionanalysts.com\/blog\/wp-content\/uploads\/2024\/08\/image-10-1.png\" alt=\"\" width=\"808\" height=\"104\" \/><\/p>\n<div class=\"card mobile-card\">\n<p><img decoding=\"async\" class=\"profile-pic\" style=\"width: 9em;\" src=\" https:\/\/www.solutionanalysts.com\/blog\/wp-content\/uploads\/2024\/08\/rajan_shah.jpg\" alt=\"Profile Picture\" \/><\/p>\n<div class=\"card-content\">\n<p><span style=\"font-weight: 400;\"><b>Rajan Shah<\/b><\/span><\/p>\n<p class=\"title\">Technical Manager<\/p>\n<p>Rajan Shah is a Technical Manager at Solution Analysts. He brings almost a decade of experience and a genuine passion for software development to his role. He&#8217;s a skilled problem solver with a keen eye for detail, his expertise spans in a diverse range of technologies including Ionic, Angular, Node.js, Flutter, and React Native, PHP, and iOS.<\/p>\n<div class=\"social-links\"><a href=\"https:\/\/www.linkedin.com\/in\/rajan-shah-81a3b115\/\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\" https:\/\/www.solutionanalysts.com\/blog\/wp-content\/uploads\/2024\/08\/link.png\" alt=\"LinkedIn\" \/><\/a><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0Installing Node.js on Ubuntu is a simple procedure that requires only a few steps. Node.js is a popular JavaScript runtime based on Chrome&#8217;s V8 JavaScript engine that is commonly used for developing server-side applications. This tutorial will help you through the installation steps. Let&#8217;s have a look at the steps for install Node.js on Ubuntu.\u00a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":39353,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128],"tags":[555,556,402],"class_list":["post-39343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js","tag-install-node-js-on-ubuntu","tag-node-js-on-ubuntu","tag-nodejs"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/posts\/39343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/comments?post=39343"}],"version-history":[{"count":30,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/posts\/39343\/revisions"}],"predecessor-version":[{"id":40490,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/posts\/39343\/revisions\/40490"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/media\/39353"}],"wp:attachment":[{"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/media?parent=39343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/categories?post=39343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/tags?post=39343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}