{"componentChunkName":"component---src-templates-post-js","path":"/post/installing-node-js-tutorial-using-nvm-on-mac-os-x-and-ubuntu","result":{"data":{"contentfulHero":{"coverImage":{"file":{"url":"//images.ctfassets.net/xmu5vdhtphau/1jqMTE2RJBiMLIcZAnu6It/5495c6ec7df10a55768df442e73fe4b2/home-hero-min.jpg","fileName":"home-hero-min.jpg"}}}},"pageContext":{"post":{"id":"c1d17100-3e33-50f0-97fb-8fd53ef47d1f","slug":"installing-node-js-tutorial-using-nvm-on-mac-os-x-and-ubuntu","title":"Installing Node.js Tutorial: Using nvm","createdAt":"May 16, 2020","tweetText":null,"type":"blog","video":null,"podcast":null,"categories":[{"id":"50768c9e-fc69-55ce-8a68-88617e5bcfbd","name":"How To","slug":"how-to"},{"id":"4384d042-dd09-5c7b-967b-95eab1334a2c","name":"Node.js","slug":"node-js"},{"id":"a397ebc3-492b-5568-b45d-6d4aa9722be7","name":"Tutorials","slug":"tutorials"}],"image":{"file":{"url":"//images.ctfassets.net/xmu5vdhtphau/1p4eEtLFdGcVSekU5ZnCTi/7544a13de1bae997de913ce0609374eb/15-min.png","fileName":"15-min.png"}},"author":{"name":"NodeSource","bio":{"childMarkdownRemark":{"html":"<p>This blog post was first published in NodeSource blog. Find out more <a href=\"https://nodesource.com/blog\">here</a></p>"}},"avatar":{"file":{"fileName":"mark-circle-light-1-solid@4x.png","url":"//images.ctfassets.net/xmu5vdhtphau/6TzBUzOu342mquRuYsxWhj/27416699cd376436863f29e85851ff19/mark-circle-light-1-solid_4x.png"}}},"bodyContent":{"childMarkdownRemark":{"html":"<p>This article was first published in <a href=\"https://nodesource.com/blog/installing-node-js-tutorial-using-nvm-on-mac-os-x-and-ubuntu/\">NodeSource blog</a> on January 2017.</p>\n<p>As with any programming language, platform, or tool, the first step to using it is getting it installed. Many of them typically come with a speedy way to upgrade when a new version is available. </p>\n<p>By default, there's not a way to upgrade the version of Node.js you've got from within Node.js itself. That said, there's a fantastic tool for the community called <a href=\"https://github.com/creationix/nvm\">nvm</a> that allows you to manage the versions of Node.js that you've got installed locally. </p>\n<p>One awesome aspect of <code>nvm</code> is that it <em>manages</em> the versions of Node.js, it doesn't just upgrade them. This means you can have the latest version of Node.js, the latest versions of all the LTS release lines, and any number of other versions you want to use or test as well.</p>\n<p>In this quick tutorial, we'll take a look at how to install nvm, and then how to start using it as your version manager for Node.js. Once we've completed the tutorial, you'll be ready to take the next step with Node.js.</p>\n<p>This guide covers installing nvm on macOS and Linux - note that all versions of Node.js may not support <em>every</em> version of macOS or Linux.  </p>\n<h2>Step 0: The Quick Guide (TL;DR) to Get Node.js Installed using nvm</h2>\n<p>Here's the abbreviated guide, highlighting the major steps:</p>\n<ul>\n<li>\n<p>Download the nvm install script via cURL: </p>\n<ul>\n<li><code>curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash</code></li>\n</ul>\n</li>\n<li>Ensure that nvm was installed correctly with <code>nvm --version</code>, which should return the version of nvm installed.</li>\n<li>\n<p>Install the version of Node.js you want</p>\n<ul>\n<li>Install the latest version with <code>nvm install node</code></li>\n<li>Use the latest version with <code>nvm use node</code></li>\n<li>Install the latest LTS version with <code>nvm install --lts</code></li>\n<li>Use the latest LTS verison with <code>nvm use --lts</code></li>\n</ul>\n</li>\n</ul>\n<h2>Step 1 (Optional): Ensure your system has the appropriate C++ compiler</h2>\n<p>In some cases, like when installing Node.js releases from their source or installing versions of Node.js <em>before</em> <code>0.8.6</code> (when the project started shipping binaries), you'll need to ensure that your system has the appropriate C++ build tools.</p>\n<p>For LTS and modern releases, you <strong>will not need this step</strong>. That said, it's a <em>nice to have</em> to ensure that the majority of requirements are met in any scenario.</p>\n<p>On <strong>macOS</strong>, you've got two options for a C++ compiler: the full XCode application or the stand-alone Command Line Tools portion of Xcode. </p>\n<p>To get these on macOS, you can follow these steps:</p>\n<ul>\n<li>Open your terminal of choice</li>\n<li>\n<p>Run <code>xcode-select --install</code> as a command</p>\n<ul>\n<li>A popup will appear</li>\n<li>Select <code>Install</code></li>\n</ul>\n</li>\n<li>Allow the download to run to completion</li>\n<li>If the installation went uninterrupted, you should have the necessary tools to use nvm! </li>\n</ul>\n<p>On <strong>Linux</strong>, the C++ compiler will vary from distribution to distribution. For example, on Debian and Ubuntu, you'll need to install <code>build-tools</code> and <code>libssl-dev</code>, but this may be different on your given Linux distribution.</p>\n<p>To get <code>build-tools</code> and <code>libssl-dev</code> on Debuan and Ubuntu distributions, you can run these commands:</p>\n<pre><code class=\"language-plain\">sudo apt-get install build-essential # Install the build-essential package - let this run to completion\n\nsudo apt-get install libssl-dev # Install the libssl-dev package - also let this one run to completion\n</code></pre>\n<h2>Step 2: Download nvm with the install script</h2>\n<p>Once you've got the right C++ compiler for your system, now it's time to run the nvm install script. Here are the single-step install scripts for both macOS and Linux. You've got the option of cURL or Wget but both achieve the same result. </p>\n<p><em>Note:</em> If your Linux system doesn't have either cURL or Wget, you can run <code>sudo apt-get install curl</code> and use the cURL method.</p>\n<h3>Running the Install Script with cURL:</h3>\n<p>To install nvm with the cURL method, run the following command in your terminal:</p>\n<pre><code class=\"language-plain\">curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash\n</code></pre>\n<h3>Using the Install Script with Wget:</h3>\n<p>To install nvm with the Wget method, run the following command in your terminal:</p>\n<pre><code class=\"language-plain\">wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash\n</code></pre>\n<h2>Step 3: Verify that nvm was Properly installed</h2>\n<p>After running the install script from Step 2, nvm should have successfully installed. To ensure that nvm is up and running on your machine, you can test it with the following command:</p>\n<pre><code class=\"language-plain\">nvm --version\n</code></pre>\n<p>This command will return something like (though not necessarily exactly) the following: </p>\n<pre><code class=\"language-plain\">nvm --version # The command we ran - it checks the currently installed version of nvm\n0.33.0 # The current version of nvm - yours may differ!\n</code></pre>\n<h3>Missing the <code>nvm</code> command after running the install script?</h3>\n<p>If you're using macOS, you may be missing a <code>.bash_profile</code> file - to troubleshoot this, you can run <code>touch ~/.bash_profile</code> in your command line and re-run the installer script.</p>\n<p>If the problem persists after that, you can open the existing <code>.bash_profile</code> file (using your favorite text editor) and add the following line to it:</p>\n<pre><code class=\"language-plain\">source ~/.bashrc\n</code></pre>\n<p>If you're still having issues, you can take a peek at <a href=\"https://github.com/creationix/nvm/issues/576\">this issue</a> to find a discussion of the problem and a collection of possible resolutions.</p>\n<h2>Step 3: Using nvm to manage Node.js</h2>\n<p>Congratulations! You've now got <code>nvm</code> - a tool to <em>easily</em> allow you to manage and swap out the versions of Node.js you've got installed locally. Now, let's get you started with doing just that.</p>\n<h3>Install the latest Node.js version</h3>\n<p>To install the latest available version of Node.js, you can use the following command: </p>\n<pre><code class=\"language-plain\">nvm install node\n</code></pre>\n<p>Next, to <em>use</em> that version of Node.js in any new shell, you can simply run the <code>use</code> command:</p>\n<pre><code class=\"language-plain\">nvm use node\n</code></pre>\n<h3>Install the latest Node.js LTS version</h3>\n<p>To install the latest available <em>LTS</em> version of Node.js, you can run the following command: </p>\n<pre><code class=\"language-plain\">nvm install --lts\n</code></pre>\n<p>And to use that latatestTS version of Node.js in any new shell, you can simply run the <code>use</code> command:</p>\n<pre><code class=\"language-plain\">nvm use --lts\n</code></pre>\n<h2>Step 6: Go build applications, APIs, tools, and more with Node.js!</h2>\n<p>Now you've got a fantastic version manager for Node.js. It's time to start building!</p>\n<div class=\"blog-cta nsolid\">\n\tGet unparalleled visibility into application performance and system health.\n  <a class=\"button more large\" href=\"https://accounts.nodesource.com/sign-up-blogref/?utm_campaign=blogref&utm_source=blog&utm_content=blog-install-nvm\">Get started with N|Solid today</a>\n</div>\n<p>We've got some resources to get you kickstarted! Both the breadth and depth of the Node.js and the JavaScript ecosystems are quite large - in addition to the developer tools like <a href=\"https://nodesource.com/products/nsolid\">NodeSource N|Solid</a> and <a href=\"https://certified.nodesource.com/\">Certified Modules</a>, we've got a ton of tutorials, guides, and articles to help you get kick started with Node.js.</p>\n<p>If you're interested in keeping your code clean, maintainable, and collaborative, take a peek at our post on <a href=\"https://nodesource.com/blog/streamline-javascript-development-with-eslint\">using ESLint for linting your JavaScript applications</a>. Are you interested in building web applications with Node.js? One of the most challenging aspects of web apps is security - you can learn <a href=\"https://nodesource.com/blog/nine-security-tips-to-keep-express-from-getting-pwned\">security best practices for Express</a> to lock down your web apps, to prevent breaches and attacks. Or, maybe you want to deploy your Node.js apps with Docker? Then you should <em>definitely</em> read our article on <a href=\"https://nodesource.com/blog/8-protips-to-start-killing-it-when-dockerizing-node-js\">dockerizing your Node.js applications</a>.</p>\n<p>That said, if you want to keep in touch with the Node.js ecosystem, you should follow <a href=\"http://twitter.com/nodesource\">@NodeSource</a> on Twitter! We'll keep you updated with important news from the core Node.js project, fresh and useful Node.js tutorials, and more.</p>"}}}}}}