How to Install NPM on Fedora 39, 38 Linux

This guide is designed to demonstrate the process of setting up NPM, Node Package Manager, on a Fedora Linux system. NPM is an essential tool in web development, offering a vast repository of packages that simplify and enhance the development process. Whether you’re a seasoned developer or starting out, mastering NPM on Fedora can significantly streamline your workflow. Below, we’ll explore the key features of NPM and provide step-by-step instructions to get you up and running smoothly.

Key Features of NPM:

  • Package Management: Simplifies the addition, update, and removal of software packages.
  • Extensive Repository: Access to a large collection of JavaScript and Node.js packages.
  • Project Management: Efficiently manages project dependencies and version control.
  • Community Driven: Benefits from a vast and active community, offering support and contributions.

After familiarizing yourself with these features, you’ll find that NPM is more than just a package manager; it’s a powerful tool that enhances your development experience on Fedora Linux. Now, let’s dive into the specifics of installing and utilizing NPM to its fullest potential.

Install NPM on Fedora Linux via Default Appstream

Step 1: Install NPM via DNF Command

To begin installing NPM on your Fedora system, launch the terminal. In the terminal, execute the command:

sudo dnf install npm

This command utilizes the DNF package manager, native to Fedora, to install the NPM package. The -y flag is appended to automatically confirm and process any prompts that may arise during the installation.

Step 2: Confirm Appstream NPM Installation

After completing the installation, verify that NPM is correctly installed. To do this, input the following command in your terminal:

npm --version

Executing this command will display the current version of NPM installed on your system, confirming the success of the installation.

Step 3: Update NPM on Fedora

Maintaining the latest version of NPM is crucial for security and access to the latest features. Update NPM to the latest version using the command:

sudo npm install -g npm@latest

This command upgrades NPM to the most recent version available. The -g flag specifies that the update applies globally across the system, making the updated version accessible to all users. This global installation is vital for a consistent development environment, especially in multi-user setups.

Install NPM with NodeSource Repository

Step 1: Import NodeSource LTS or Latest Stable

Selecting the right version of Node.js is a critical first step. NodeSource provides two main options: the LTS (Long Term Support) version for enhanced stability and extended support, and the latest stable version that includes the newest features. Your choice depends on your project’s requirements for stability versus cutting-edge capabilities.

Option 1: Import NodeSource LTS

To access the LTS version, which is recommended for its robustness and long-term support, use this command in your terminal:

curl -sL https://rpm.nodesource.com/setup_lts.x | sudo -E bash -

This command fetches and executes a script from NodeSource that configures your system to use the LTS repository.

Option 2: Import NodeSource Latest Stable

For the latest features and improvements, import the latest stable repository with this command:

curl -sL https://rpm.nodesource.com/setup_stable.x | sudo -E bash -

This command will set up your Fedora system to receive Node.js and NPM packages from the latest stable NodeSource repository.

Step 2: Install NPM via NodeSource RPM

After importing the preferred NodeSource repository, install NPM using the DNF package manager. Run the following command:

sudo dnf install npm

Step 3: Confirm Installation

Verify the successful installation of NPM by checking its version. Type the following command:

npm --version

This command will display the installed version of NPM, confirming the installation.

Step 4: Update NPM

To ensure you’re using the most recent version of NPM, which can include crucial updates and security patches, run this update command:

sudo npm install -g npm@latest

The -g flag in this command specifies a global installation, making the latest version of NPM available to all users on your system.

Common NPM Command Examples on Fedora Linux

This section will cover some common NPM commands that you may find useful while working with Node.js projects. A brief explanation and an example will accompany each command.

npm init

Use this command to start a new Node.js project. It generates a package.json file, a crucial component that holds project details such as dependencies and scripts. This file is fundamental for managing the project’s packages and configurations.

npm init

npm install <package-name>

This command adds a specific package to your project as a dependency. Substitute <package-name> with the actual package you need. The installation is local to the project, ensuring the package versions are controlled and consistent across environments.

npm install express

npm install -g <package-name>

To install a package globally, use this command. It makes the package accessible to all users on the system. This is particularly useful for tools and utilities you need across multiple projects.

Replace <package-name> with your desired package.

npm install -g nodemon

npm uninstall <package-name>

This command is used to remove a package from your project’s dependencies. Enter the specific package name in place of <package-name>. It’s a good practice to keep your project dependencies tidy and up-to-date.

npm uninstall express

npm update

Run this command to update all packages in your project to their latest versions. It helps in keeping your project secure and efficient by utilizing the most recent package updates and bug fixes.

npm update

npm list

This command provides a tree view of all installed dependencies in your project. It’s a quick way to visually inspect the packages included in your project and their respective versions.

npm list

npm run <script-name>

Use this to execute a script defined in your package.json file. Replace <script-name> with the name of the script you want to run. This is commonly used for tasks like starting the project, testing, or custom scripts defined for automation.

npm run start

Conclusion

Throughout this guide, we’ve navigated through two practical approaches on how to install NPM on Fedora Linux, utilizing the Fedora and NodeSource repositories. Each method caters to distinct needs, offering flexibility in setting up your development environment. With the clear, step-by-step instructions, you’re now well-equipped to install NPM and adeptly handle your Node.js projects. As you move forward, remember the various NPM commands we discussed.

Leave a Comment