<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mumenya Nyamu</title>
    <description>The latest articles on DEV Community by Mumenya Nyamu (@mumenyam).</description>
    <link>https://dev.to/mumenyam</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F128949%2F81be53e1-5849-4a1a-a11a-7652027a2e63.jpeg</url>
      <title>DEV Community: Mumenya Nyamu</title>
      <link>https://dev.to/mumenyam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mumenyam"/>
    <language>en</language>
    <item>
      <title>How To manage Different Versions of Node in Your system</title>
      <dc:creator>Mumenya Nyamu</dc:creator>
      <pubDate>Fri, 28 Apr 2023 09:59:57 +0000</pubDate>
      <link>https://dev.to/mumenyam/node-series-2cj5</link>
      <guid>https://dev.to/mumenyam/node-series-2cj5</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbtdo1j6jzzpp3pazz71b.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbtdo1j6jzzpp3pazz71b.jpg" alt="Node Logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Web developers need &lt;code&gt;npm&lt;/code&gt;(node package manager) to manage resources, be it Angular, React, React-frameworks(Next.js and Remix), or any frontend resource. &lt;br&gt;
&lt;code&gt;npm&lt;/code&gt; ships with Node.js.&lt;/p&gt;

&lt;p&gt;To get started you need to install Node from the &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;. Download the version specific to your operating system.&lt;/p&gt;

&lt;p&gt;To update &lt;code&gt;node&lt;/code&gt; and &lt;code&gt;npm&lt;/code&gt; to the latest versions, Dillion Megida has a great &lt;a href="https://www.freecodecamp.org/news/how-to-update-node-and-npm-to-the-latest-version/" rel="noopener noreferrer"&gt;article&lt;/a&gt; at freecodecamp.&lt;/p&gt;

&lt;p&gt;There is so much more to &lt;code&gt;Node&lt;/code&gt; than just &lt;code&gt;npm&lt;/code&gt; however for this article, I want to focus on the management of &lt;code&gt;node&lt;/code&gt; or &lt;code&gt;npm&lt;/code&gt; versions. &lt;/p&gt;

&lt;p&gt;Some reasons you may want to have different node versions are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Compatibility: Some applications or projects may require a specific version of Node.js to run properly. Having multiple versions of Node.js installed on your system allows you to switch between them as needed, depending on the specific requirements of the project you are working on. For example the Angular CLI only uses lts(long-term support) versions of Node, and you may want the latest version which has the latest packages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing: If you are a developer, you may need to test your code on multiple versions of Node.js to ensure that it works correctly on different environments. Having multiple versions installed on your system allows you to test your code against different versions without having to set up separate virtual machines or other environments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dependency Management: If you are working on a project with multiple developers, each of them may have a different version of Node.js installed on their system. To ensure that everyone is working with the same version of Node.js, you can specify the required version in your project's package.json file. This way, when someone installs your project's dependencies, they will automatically get the required version of Node.js installed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can check your node version by running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
 an alias for &lt;code&gt;node --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To manage Node I recommend using two resources. This will help you install as well as use the node version of your choice.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; You can use the node package &lt;a href="https://www.npmjs.com/package/n" rel="noopener noreferrer"&gt;n&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;You can use &lt;a href="https://github.com/nvm-sh/nvm" rel="noopener noreferrer"&gt;nvm&lt;/a&gt; the node version manager.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;1 - &lt;code&gt;n&lt;/code&gt; is a tool that allows you to easily switch between different versions of Node.js. Follow the &lt;a href="https://www.npmjs.com/package/n" rel="noopener noreferrer"&gt;official guide&lt;/a&gt; in case this does not work for you due to an update or need a command not highlighted below.&lt;br&gt;
Here's how you can use n to switch between Node.js versions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install n globally using npm:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g n
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;List the available versions of Node.js using n:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;n ls
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br&gt;
This will display a list of all the Node.js versions that are currently installed on your system.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To switch to a specific version of Node.js, use the n command followed by the version number:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;n &amp;lt;version&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
For example, to switch to Node.js version &lt;code&gt;14.17.0&lt;/code&gt;, you can use the command:&lt;br&gt;
&lt;/p&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;n 14.17.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
 This will download and install the specified version of Node.js, and then switch to it. To verify that you're now using the correct version of Node.js, you can run the node -v command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
 This should display the version number of the Node.js version that you just switched to.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To switch back to the system default version of Node.js, you can use the n command without any argument:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  n
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;This will switch back to the system's default version of Node.js.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Other commands you might find useful:

&lt;ul&gt;
&lt;li&gt;To install the latest version for long-term support &lt;code&gt;n lts&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;To install the latest version &lt;code&gt;n latest&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;To remove some cached versions &lt;code&gt;n rm 0.9.4 v0.10.0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;To remove all cached versions except the installed version &lt;code&gt;n prune&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;To see remote versions available for download:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;n ls-remote lts&lt;/code&gt; for the latest lts remote version available&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;n ls-remote latest&lt;/code&gt; for the latest remote version available&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;n lsr &amp;lt;version num&amp;gt;&lt;/code&gt; to see all sub-versions produced for a particular version . can use &lt;code&gt;n lsr 16&lt;/code&gt; to see all sub-versions under version 16.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;n --all lsr&lt;/code&gt; for all remote versions available &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;2 -  Use &lt;code&gt;nvm&lt;/code&gt; the node version manager.&lt;br&gt;
This is very similar to &lt;code&gt;n&lt;/code&gt;. Its installation however requires you to use the scripts or terminal. In macOS you can use homebrew to install it. For different OS however, its best to follow the &lt;a href="https://github.com/nvm-sh/nvm#installing-and-updating" rel="noopener noreferrer"&gt;official guide&lt;/a&gt;.&lt;br&gt;
Upon installation to manage different node versions:&lt;br&gt;
     - &lt;code&gt;nvm install &amp;lt;version&amp;gt;&lt;/code&gt; installs a specific version.&lt;br&gt;
     - &lt;code&gt;nvm uninstall &amp;lt;version&amp;gt;&lt;/code&gt; uninstalls a specific version&lt;br&gt;
     - &lt;code&gt;nvm use &amp;lt;version&amp;gt;&lt;/code&gt; uses a specific version.&lt;br&gt;
     - &lt;code&gt;nvm alias default &amp;lt;version&amp;gt;&lt;/code&gt; makes a particular version the default for your system.&lt;br&gt;
     - &lt;code&gt;nvm ls-remote&lt;/code&gt; view the list of available Node.js versions that you can install.&lt;/p&gt;

&lt;p&gt;Having multiple versions of Node.js installed on your system can help you avoid compatibility issues and ensure that your applications or projects run smoothly on different environments.&lt;/p&gt;

</description>
      <category>node</category>
      <category>webdev</category>
      <category>learning</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
