{"id":1471,"date":"2021-12-07T16:25:30","date_gmt":"2021-12-07T15:25:30","guid":{"rendered":"https:\/\/nguenkam.com\/blog\/?p=1471"},"modified":"2023-01-17T10:54:08","modified_gmt":"2023-01-17T09:54:08","slug":"how-to-update-node-js-to-latest-version","status":"publish","type":"post","link":"https:\/\/nguenkam.com\/blog\/index.php\/2021\/12\/07\/how-to-update-node-js-to-latest-version\/","title":{"rendered":"How to Update Node.js to Latest Version"},"content":{"rendered":"\n<p><strong>Node.js<\/strong>&nbsp;is an open-source JavaScript runtime environment. Since Node.js has an active community of users, minor updates of the software come out every few weeks.<\/p>\n\n\n\n<p>We have to make sure to update Node.js regularly to ensure system security, and there are several ways we can do it, depending on the operating system running on our machine. (Linux  \/ Windows \/ macOs )<\/p>\n\n\n\n<h4>Update Node.js to Latest Version on Windows <\/h4>\n\n\n\n<p>Updating Node.js on Windows and macOS follows the same principles.<\/p>\n\n\n\n<p>There are two simple ways to upgrade:<\/p>\n\n\n\n<ol><li><em>Download the latest Node.js release from its official download page and install the new Node.js release.<\/em><\/li><li><em>Install the n module and update Node.js inside the terminal window.<\/em><\/li><\/ol>\n\n\n\n<p><\/p>\n\n\n\n<h5><span class=\"has-inline-color has-vivid-red-color\">Option 1: <\/span>Update Node.js with Installer<\/h5>\n\n\n\n<p>One way to update your Node.js is to go to its official download page (<span class=\"has-inline-color has-vivid-cyan-blue-color\">https:\/\/nodejs.org\/en\/<\/span>) and install the newest release. <strong><em>By doing so, the system should overwrite the older version with the updated one.<\/em><\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h5><span class=\"has-inline-color has-vivid-red-color\">Option 2:<\/span> Update Node.js  with NPM<\/h5>\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<p><\/p>\n\n\n\n<h5><span class=\"has-inline-color has-vivid-red-color\">Option 3<\/span> : Update Node.js with nvm<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>nvm install NEW_VERSION --reinstall-packages-from=OLD_VERSION\n\/\/ For example:\nnvm install 6.7 --reinstall-packages-from=6.4<\/code><\/pre>\n\n\n\n<p>then, if you want, you can delete your previous version with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nvm uninstall OLD_VERSION\n\/\/ For example:\nnvm uninstall 6.4<\/code><\/pre>\n\n\n\n<p>Alternatively, try:<\/p>\n\n\n\n<p><strong>Latest version<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nvm install node --reinstall-packages-from=node<\/code><\/pre>\n\n\n\n<p><strong>Stable (LTS) version<\/strong>: (if currently in use)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nvm install \"lts\/*\" --reinstall-packages-from=\"$(nvm current)\"<\/code><\/pre>\n\n\n\n<p>This will install the appropriate version and reinstall all packages from the currently used node version.<\/p>\n\n\n\n<p>This saves you from manually handling the specific versions.<\/p>\n\n\n\n<h5>RESUME : <\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>nvm install &lt;version>\n\n\/\/Check the list of available Node.js version in the system using the following command:\nnvm list \n\n\/\/ To use the desired version, use the following command:\nnvm use &lt;version><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Node.js&nbsp;is an open-source JavaScript runtime environment. Since Node.js has an active community of users, minor updates of the software come out every few weeks. We have to make sure to update Node.js regularly to ensure system security, and there are several ways we can do it, depending on the operating system running on our machine. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[145],"tags":[184,197,308],"_links":{"self":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1471"}],"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=1471"}],"version-history":[{"count":4,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1471\/revisions"}],"predecessor-version":[{"id":2467,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1471\/revisions\/2467"}],"wp:attachment":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}