{"id":11456,"date":"2021-10-29T10:42:40","date_gmt":"2021-10-29T10:42:40","guid":{"rendered":"https:\/\/linuxways.net\/?p=11456"},"modified":"2021-10-29T10:42:40","modified_gmt":"2021-10-29T10:42:40","slug":"how-to-install-node-js-and-npm-in-ubuntu","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-node-js-and-npm-in-ubuntu\/","title":{"rendered":"How to Install Node.js and Npm in Ubuntu?"},"content":{"rendered":"<h2>What is Node.js?<\/h2>\n<p>Node.js is an open-source and cross-platform JavaScript runtime environment. Usually, JavaScript is associated with web development and browser executions.<\/p>\n<p>But Node.js enables its user to run JavaScript as a stand-alone application, on any medium. It means you can run JavaScript outside the browser.<\/p>\n<h2>What is Npm?<\/h2>\n<p>Node Package Manager (npm) is both an online repository for modules and packages of Node.js, and a command-line utility for installation, version, and dependency management.<\/p>\n<p>Npm is easy to use and makes working with Node.js very convenient. Additionally, npm comes with Node.js installation so you do not have to install it separately.<\/p>\n<p>In this article, you will learn about different methods to install Node.js and Npm in your Ubuntu operating system.<\/p>\n<h2>Prerequisites<\/h2>\n<p>Linux-based system<\/p>\n<p>Terminal access<\/p>\n<p>A user account with sudo privileges.<\/p>\n<h2>Install Node.js Ubuntu Package Using apt<\/h2>\n<p>You will need a curl command to enable the NodeSource repository. If you lack curl on your system, install curl on your system using the following command.<\/p>\n<pre>sudo apt-get install curl<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1419\" height=\"571\" class=\"wp-image-11457\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-508.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-508.png 1419w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-508-300x121.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-508-1024x412.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-508-768x309.png 768w\" sizes=\"auto, (max-width: 1419px) 100vw, 1419px\" \/><\/p>\n<p>To enable the NodeSource repository and update the apt-cache. run the following command.<\/p>\n<pre>curl -sL https:\/\/deb.nodesource.com\/setup_12.x | sudo -E bash -<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1429\" height=\"857\" class=\"wp-image-11458\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-509.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-509.png 1429w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-509-300x180.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-509-1024x614.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-509-768x461.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-509-501x300.png 501w\" sizes=\"auto, (max-width: 1429px) 100vw, 1429px\" \/><\/p>\n<p>Now you can go ahead and install the Node.js package with the following apt command.<\/p>\n<pre>sudo apt install nodejs<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1414\" height=\"575\" class=\"wp-image-11459\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-510.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-510.png 1414w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-510-300x122.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-510-1024x416.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-510-768x312.png 768w\" sizes=\"auto, (max-width: 1414px) 100vw, 1414px\" \/><\/p>\n<p>You can see the Node.js version with the following command.<\/p>\n<pre>node --version<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1417\" height=\"112\" class=\"wp-image-11460\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-511.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-511.png 1417w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-511-300x24.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-511-1024x81.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-511-768x61.png 768w\" sizes=\"auto, (max-width: 1417px) 100vw, 1417px\" \/><\/p>\n<p>As npm comes with the Node.js installation, you can check the npm version with the following command.<\/p>\n<pre>npm --version<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1416\" height=\"108\" class=\"wp-image-11461\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-512.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-512.png 1416w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-512-300x23.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-512-1024x78.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-512-768x59.png 768w\" sizes=\"auto, (max-width: 1416px) 100vw, 1416px\" \/><\/p>\n<h2>Install Node.js With PPA Software Repository Using apt<\/h2>\n<p>If you want your repository to be self-maintained and updated so that you can work with the latest version of Node.js, you can use the NodeSource PPA for Node.js installation.<\/p>\n<p>Install the NodeSource PPA with the following curl command.<\/p>\n<pre>curl -sL https:\/\/deb.nodesource.com\/setup_16.x -o nodesource_setup.sh<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1407\" height=\"127\" class=\"wp-image-11462\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-513.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-513.png 1407w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-513-300x27.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-513-1024x92.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-513-768x69.png 768w\" sizes=\"auto, (max-width: 1407px) 100vw, 1407px\" \/><\/p>\n<p>Open the Nodesource setup script with nano editor and verify the configurations.<\/p>\n<pre>nano nodesource_setup.sh<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1416\" height=\"917\" class=\"wp-image-11463\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-514.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-514.png 1416w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-514-300x194.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-514-1024x663.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-514-768x497.png 768w\" sizes=\"auto, (max-width: 1416px) 100vw, 1416px\" \/><\/p>\n<p>To add the PPA to the configuration list and update the local cache, run the script.<\/p>\n<pre>sudo bash nodesource_setup.sh<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1420\" height=\"837\" class=\"wp-image-11464\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-515.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-515.png 1420w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-515-300x177.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-515-1024x604.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-515-768x453.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-515-1020x600.png 1020w\" sizes=\"auto, (max-width: 1420px) 100vw, 1420px\" \/><\/p>\n<p>Now you can install Node.js with the following command.<\/p>\n<pre>sudo apt install nodejs<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1412\" height=\"546\" class=\"wp-image-11465\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-516.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-516.png 1412w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-516-300x116.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-516-1024x396.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-516-768x297.png 768w\" sizes=\"auto, (max-width: 1412px) 100vw, 1412px\" \/><\/p>\n<p>To verify the installation and version of Node.js, run.<\/p>\n<pre>node -v<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1422\" height=\"116\" class=\"wp-image-11466\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-517.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-517.png 1422w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-517-300x24.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-517-1024x84.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-517-768x63.png 768w\" sizes=\"auto, (max-width: 1422px) 100vw, 1422px\" \/><\/p>\n<h2>Install NVM for Node.js Installation and Version Management<\/h2>\n<p>Node Version Manager (NVM) is a script that helps with the installation and management of multiple versions of Node.js in your system.<\/p>\n<p>Download NVM from the GitHub repository with the following curl command.<\/p>\n<pre>curl -o- https:\/\/raw.githubusercontent.com\/nvm-sh\/nvm\/v0.35.3\/install.sh | bash<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1416\" height=\"596\" class=\"wp-image-11467\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-518.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-518.png 1416w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-518-300x126.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-518-1024x431.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-518-768x323.png 768w\" sizes=\"auto, (max-width: 1416px) 100vw, 1416px\" \/><\/p>\n<p>You can see that the installation has made changes to the .bashrc file. Source your.bashrc file with the following command to proceed with the installation.<\/p>\n<pre>source ~\/.bashrc<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1424\" height=\"131\" class=\"wp-image-11468\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-519.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-519.png 1424w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-519-300x28.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-519-1024x94.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-519-768x71.png 768w\" sizes=\"auto, (max-width: 1424px) 100vw, 1424px\" \/><\/p>\n<p>To see available versions of Node.js, run the following command.<\/p>\n<pre>nvm list-remote<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1413\" height=\"501\" class=\"wp-image-11469\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-520.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-520.png 1413w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-520-300x106.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-520-1024x363.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-520-768x272.png 768w\" sizes=\"auto, (max-width: 1413px) 100vw, 1413px\" \/><\/p>\n<p>Select the version and run the following command with your selected version.<\/p>\n<pre>nvm install v17.0.1<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1413\" height=\"578\" class=\"wp-image-11470\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-521.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-521.png 1413w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-521-300x123.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-521-1024x419.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-521-768x314.png 768w\" sizes=\"auto, (max-width: 1413px) 100vw, 1413px\" \/><\/p>\n<p>To see all the Node.js installations in your system, run the following command.<\/p>\n<pre>nvm list<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1423\" height=\"495\" class=\"wp-image-11471\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-522.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-522.png 1423w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-522-300x104.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-522-1024x356.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-522-768x267.png 768w\" sizes=\"auto, (max-width: 1423px) 100vw, 1423px\" \/><\/p>\n<p>You can see the current version that is in use mentioned in the first line of the output.<\/p>\n<p>You can switch to another installed version and use it with the following command.<\/p>\n<pre>nvm use 17.0.1<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1417\" height=\"181\" class=\"wp-image-11472\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-523.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-523.png 1417w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-523-300x38.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-523-1024x131.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-523-768x98.png 768w\" sizes=\"auto, (max-width: 1417px) 100vw, 1417px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, you have learned about the different methods to install Node.js in your Ubuntu system. While installing Node.js, the fastest and easiest way is to use the default Ubuntu package, but if You need a more updated and maintained installation, You can choose the NodeSource PPA. However, the most flexible and recommended method is to use NVM to install Node.js as it can install and manage multiple versions side by side.<\/p>","protected":false},"excerpt":{"rendered":"<p>What is Node.js? Node.js is an open-source and cross-platform JavaScript runtime environment. Usually, JavaScript is associated with web development and browser executions. But Node.js enables its user to&hellip;<\/p>","protected":false},"author":1,"featured_media":11699,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[259,651,100],"class_list":["post-11456","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-node-js","tag-npm","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/11456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=11456"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/11456\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/11699"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=11456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=11456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=11456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}