<?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>Forem: Matteo Veraldi</title>
    <description>The latest articles on Forem by Matteo Veraldi (@mattveraldi).</description>
    <link>https://forem.com/mattveraldi</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%2F1218774%2Fd19bb7c1-2e66-4208-86a4-a4cc0075b5c6.png</url>
      <title>Forem: Matteo Veraldi</title>
      <link>https://forem.com/mattveraldi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mattveraldi"/>
    <language>en</language>
    <item>
      <title>How to quickly setup NodeJS with NVM</title>
      <dc:creator>Matteo Veraldi</dc:creator>
      <pubDate>Sun, 17 Dec 2023 15:29:49 +0000</pubDate>
      <link>https://forem.com/mattveraldi/how-to-quickly-setup-nodejs-with-nvm-2ldj</link>
      <guid>https://forem.com/mattveraldi/how-to-quickly-setup-nodejs-with-nvm-2ldj</guid>
      <description>&lt;p&gt;If you'd like to see the video version &lt;a href="https://bit.ly/mattveraldi-setup-nodejs-yt" rel="noopener noreferrer"&gt;Click here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I had to re-install my WSL2 Ubuntu distro for Web Development, so I decided to document how I setup things starting from NodeJS.&lt;br&gt;
These steps are meant to be executed on a Debian based Linux distribution, but they are valid also for Mac OSX.&lt;/p&gt;
&lt;h2&gt;
  
  
  NodeJS
&lt;/h2&gt;

&lt;p&gt;I often switch from one project to another and each project requires a different version of NodeJS. I am too lazy to manually install and change my &lt;code&gt;PATH&lt;/code&gt; variables to perform the switch so I always install NodeJS through &lt;code&gt;nvm&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is NVM?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;NVM&lt;/code&gt; is a Node Version Manager, a &lt;code&gt;CLI&lt;/code&gt; tool for NodeJS that provides utilities to install and switch from one version of &lt;code&gt;Node&lt;/code&gt; to another in a matter of seconds.&lt;/p&gt;
&lt;h3&gt;
  
  
  Install NVM
&lt;/h3&gt;

&lt;p&gt;Open a new terminal and paste this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-o-&lt;/span&gt; https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Please note: If this post is too old, please make sure to replace &lt;code&gt;v0.39.7&lt;/code&gt; with the latest version of &lt;code&gt;nvm&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Install NodeJS via NVM
&lt;/h1&gt;

&lt;p&gt;Open a new terminal and paste this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm ls-remote
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;from the list that will appear, select the version you'd like to install. If you are not sure, install the latest Long Term Support (LTS) version with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--lts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add .nvmrc to your project
&lt;/h3&gt;

&lt;p&gt;One of the best features of &lt;code&gt;nvm&lt;/code&gt; is the &lt;code&gt;.nvmrc&lt;/code&gt;. It is a file that you can add inside the root directory of your NodeJS project to allow &lt;code&gt;nvm&lt;/code&gt; users to &lt;code&gt;install&lt;/code&gt; and &lt;code&gt;use&lt;/code&gt; the correct NodeJS version without having to think about it. It is very good for &lt;code&gt;CI/CD&lt;/code&gt; too!&lt;/p&gt;

&lt;p&gt;To create a &lt;code&gt;.nvmrc&lt;/code&gt;, open a new terminal on the root directory of your project and paste this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .nvmrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To test if it works, paste this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; nvm use
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may create a &lt;code&gt;bash&lt;/code&gt; script inside your &lt;code&gt;.bashrc&lt;/code&gt; that automatically looks for an &lt;code&gt;.nvmrc&lt;/code&gt; file in your directory and performs the &lt;code&gt;install&lt;/code&gt; and &lt;code&gt;use&lt;/code&gt; for you. &lt;a href="https://github.com/nvm-sh/nvm?tab=readme-ov-file#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file" rel="noopener noreferrer"&gt;Click here to learn how&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;This was a very quick introduction to how I setup NodeJS on my environment using &lt;code&gt;nvm&lt;/code&gt;. If you have any questions please refer to the &lt;a href="https://github.com/nvm-sh/nvm" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt; or contact me via my &lt;a href="https://mattveraldi.github.io/" rel="noopener noreferrer"&gt;Social Links&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>node</category>
      <category>nvm</category>
      <category>howto</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
