Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 3

Installing Node.js and npm on Fedora

Recommended resources

Hello! Let's continue setting up your professional development environment.

In the last lesson, you became comfortable navigating your Fedora system and managing files using the terminal. Those skills are the foundation for everything we'll do next, from version control to running development servers.

Today, we'll install two of the most critical tools in modern web development: Node.js and npm. Understanding and installing these correctly is essential for building almost any contemporary web project. This lesson directly addresses the learning outcome: Install Node.js and npm on Fedora and verify the installation.

We will cover:

  • What Node.js and npm are, and why they are indispensable for developers.
  • Why using a version manager (NVM) is the industry-standard way to install Node.js.
  • A step-by-step guide to installing these tools on your Fedora system.

1. What are Node.js and npm?

Before we install anything, it's crucial to understand what these tools are and the role they play. You've expressed a strong interest in the "why" behind development practices, and this is a perfect example.

The following video from Coder Coder provides a fantastic, beginner-friendly explanation using a great analogy.

What is NPM, and why do we need it? | Tutorial for beginners

This video, 'What is NPM, and why do we need it?', clearly explains the purpose of Node.js and its package manager, npm.

Please watch from the beginning until the timestamp 02:49. Focus on: The car-building analogy to understand why developers use 'packages'. The role of Node.js as the runtime environment. The role of npm as the package manager and command-line interface (CLI).

To summarize the key ideas from the video:

  • Node.js is a JavaScript runtime environment. In simple terms, it's what allows you to run JavaScript code outside of a web browser. This is essential for the tools that build, bundle, and serve modern websites.
  • npm (Node Package Manager) is the world's largest software registry. It's a vast library of free, reusable code packages written by other developers. Using npm, you can easily install these packages (like Vue.js, Tailwind CSS, or small helper utilities) into your projects instead of writing everything from scratch. npm is automatically installed with Node.js.

2. The Professional Approach: Using a Version Manager

There are several ways to install Node.js. You might see guides suggesting a direct installation using Fedora's package manager (e.g., sudo dnf install nodejs). While simple, this method has a major drawback: it locks you into a single version of Node.js.

In the real world, different projects often require different versions of Node.js to function correctly. This is where a Node Version Manager (NVM) becomes invaluable.

How to Install NVM on Linux (Ubuntu and Centos) - 4Geeks

This article, 'How to Install NVM on Linux', explains what NVM is and why it's so beneficial for developers.

Please read the two short sections at the end of the article titled 'What is NVM?' and 'Why Install NVM on Linux?'.

In short, NVM lets you install multiple Node.js versions on the same machine and switch between them with a simple command. This prevents version conflicts between projects and is considered a best practice in the development community. For your goal of learning industry standards, starting with NVM is the right move.


3. Hands-On Guide: Installing Node.js via NVM

Now, let's get everything installed on your Fedora system. Open your terminal and follow these steps carefully.

Step 1: Install NVM

We'll use a script to install NVM. The resource LINK provides instructions for Fedora.

  1. Install curl: This is a tool for transferring data with URLs. You may already have it, but this command will ensure it's installed.

    sudo dnf install curl
    
  2. Run the NVM installation script: The official NVM GitHub repository (which is the source for the script) recommends copying the command directly from their README to ensure you get the latest version. You can run the following command, which fetches the install script and executes it.

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    

    This command downloads the script and runs it. It will create a hidden directory in your home folder (~/.nvm) and add some lines to your shell profile file (e.g., ~/.bashrc).

  3. Apply the changes: The installation script modifies your shell's startup file, but the changes won't take effect until you source that file or restart your terminal. The easiest way is to simply close your current terminal and open a new one.

Step 2: Verify NVM Installation

In your new terminal window, run the following command:

nvm --version

You should see an output with a version number (e.g., 0.39.7). If you get a "command not found" error, review the troubleshooting guide below.

How to Install NVM on Linux (Ubuntu and Centos) - 4Geeks

If you encounter any issues, this part of the 'How to Install NVM on Linux' article offers solutions to the most common problems.

Review the 'Common Troubleshooting Steps' section, especially the first point, 'Command Not Found Error After Installation', if the nvm command does not work.

Step 3: Install Node.js

With NVM working, installing Node.js is now straightforward. We will install the latest LTS (Long-Term Support) version. LTS versions are recommended for most users as they are stable and receive support for an extended period.

The following video demonstrates the key NVM commands for listing and installing Node versions.

How to Install and Use NVM (Node Version Manager) on Mac & Linux

This clip from 'How to Install and Use NVM' shows exactly how to install Node.js using NVM.

Watch the segment from 02:41 to 03:27. Pay close attention to the command used to install the latest 'long-term support' version.

Now, run this command in your terminal:

nvm install --lts

NVM will download, compile, and install the latest LTS version of Node.js and automatically set it as your current version.

Step 4: Verify Node.js and npm Installation

Finally, let's verify that both Node.js and npm are installed and ready to use. Run these two commands separately:

node -v

This should print the version of Node.js you just installed (e.g., v20.12.2).

npm -v

This should print the corresponding version of npm (e.g., 10.5.0).

If you run npm without any arguments, you'll see a help menu, confirming it's installed correctly.

NPM Usage and Version Verification in Terminal
This is an example of the output you might see after running the `npm` command, with the version number highlighted. Your version numbers will likely be different.

Congratulations! You have now successfully installed Node.js and npm using the industry-standard version manager.


Conclusion

Great work today! You've added a crucial layer to your development environment. This setup not only equips you with the necessary tools but does so in a way that is flexible and professional.

Here are your key takeaways:

  • Node.js lets you run JavaScript outside the browser, powering modern development tools.
  • npm is the package manager for Node.js, giving you access to a vast ecosystem of reusable code.
  • NVM (Node Version Manager) is the best practice for installing Node.js, as it allows you to manage multiple versions for different projects.
  • You verified your installation using node -v and npm -v.

In our next lesson, we will install and configure Git, the final core component of your development environment. Once Git is set up, you'll have all the tools you need to start building projects with proper version control from day one.