How to Install NPM on Fedora 39/38/37 Linux

NPM, or Node Package Manager, is essential for any developer working with Node.js applications. It simplifies managing, sharing, and reusing packages (or modules) to build complex applications quickly and efficiently. This introduction will provide an overview of NPM on Fedora Linux, highlighting its main features and capabilities.

Key Features of NPM on Fedora Linux:

  1. Package Management: NPM allows developers to easily install, update, and remove packages from their projects, streamlining the development process.
  2. Dependency Management: NPM handles the complex task of managing dependencies between packages, ensuring each package has the necessary components to work correctly.
  3. Extensive Repository: With access to over a million open-source packages, NPM offers a vast ecosystem that promotes code sharing and collaboration among developers.
  4. Version Control: NPM helps maintain different versions of packages, allowing developers to work with specific versions to avoid potential conflicts or issues.
  5. Cross-Platform Compatibility: NPM is compatible with various platforms, including Fedora Linux, making it a versatile tool for developers in different environments.
  6. Scripting Support: NPM provides a way to create and run scripts that automate various tasks during development, improving efficiency and productivity.
  7. Integration with Fedora Linux: NPM can be seamlessly integrated into the Fedora Linux environment, offering an excellent package management solution for Node.js developers using this distribution.

In summary, NPM is a powerful and flexible tool that helps developers manage packages, dependencies, and scripts for their Node.js applications. It integrates smoothly with Fedora Linux, ensuring a robust development environment for creating high-quality applications. This guide will demonstrate how to install NPM (Node Package Manager) on Fedora Linux using Fedora’s default repository or importing the latest Node.js repository and installing npm with it.

Section 1: Install NPM with Fedora Repository

This section will cover how to install NPM using the Fedora repository. The Fedora repository is a software repository that comes pre-installed with your Fedora Linux system and includes the NPM package.

Step 1: Install NPM

To install NPM, open a terminal window and enter the following command:

sudo dnf install -y npm

This command tells your system to install the NPM package using the DNF package manager. The -y flag is included to confirm any prompts during the installation process automatically.

Step 2: Confirm NPM Installation

Once the installation is complete, you can confirm the successful installation of NPM by running the following command:

npm --version

This command will display the version number of your NPM, confirming that the installation was successful.

Step 3: Update NPM

To ensure you are using the latest version of NPM, you can update it with the following command:

sudo npm install -g npm@latest

This command installs the latest version of NPM globally on your system. The -g flag indicates that the package should be installed globally, making it available to all users on the system.

Section 2: Install NPM with NodeSource Repository

This section will cover how to install NPM using the NodeSource repository. NodeSource is a third-party repository that provides up-to-date Node.js and NPM packages.

Step 1: Import NodeSource LTS or Latest Stable

Before installing NPM, you must decide whether to use the LTS (Long Term Support) or the latest stable version of Node.js. Each option has benefits: the LTS version is more stable and has a longer support period, while the latest stable version has the most recent features.

Option 1: Import NodeSource LTS

To import the NodeSource LTS repository, enter the following command in your terminal:

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

Option 2: Import NodeSource Latest Stable

To import NodeSource’s latest stable repository, enter the following command in your terminal:

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

Step 2: Install NPM

Once you have imported the NodeSource repository, you can install NPM with the following command:

sudo dnf install -y npm

Step 3: Confirm Installation

To confirm the successful installation of NPM, run the following command:

npm --version

Step 4: Update NPM

Update NPM to the latest version with the following command:

sudo npm install -g npm@latest

Section 3: Common NPM Commands

This section will cover some common NPM commands that you may find useful while working with Node.js projects. Each command will be accompanied by a brief explanation and an example.

npm init

This command initializes a new Node.js project and creates a package.json file, which contains information about the project, such as its dependencies and scripts.

npm init

npm install <package-name>

This command installs a specific package as a dependency in your project. Replace <package-name> with the name of the package you wish to install.

npm install express

npm install -g <package-name>

This command installs a specific package globally, making it available to all users on the system. Replace <package-name> with the name of the package you wish to install.

npm install -g nodemon

npm uninstall <package-name>

This command removes a specific package from your project’s dependencies. Replace <package-name> with the name of the package you wish to remove.

npm uninstall express

npm update

This command updates all your project’s dependencies to their latest versions.

npm update

npm list

This command displays a tree of your project’s installed dependencies.

npm list

npm run <script-name>

This command runs a script specified in your package.json file. Replace <script-name> with the name of the script you wish to run.

npm run start

Conclusion: Installing NPM on Fedora Linux

In this guide, we explored two different methods for installing NPM on Fedora Linux: the Fedora and NodeSource repositories. Both methods have their advantages and are suitable for different use cases. By following the steps outlined in this guide, you can install NPM and successfully manage your Node.js projects. Remember to familiarize yourself with common NPM commands, which will streamline your development experience.

Additional Resources and Links

To further expand your knowledge and enhance your skills with NPM and Node.js, explore the following official resources and documentation:

  • Node.js Official Website: The main website for Node.js, containing news, updates, and downloads for the latest versions of Node.js.
  • NPM Official Website: The official NPM website features package search, documentation, and other resources to help you manage your Node.js projects.
  • Node.js Documentation: The official Node.js documentation covers various topics such as guides, API references, and FAQs.
  • NPM Documentation: The official NPM documentation provides detailed information on NPM commands, package management, and configuration options.
  • Fedora Project Wiki: The Fedora Project Wiki, a valuable resource for Fedora users, contains articles, guides, and community-driven content related to Fedora Linux and its ecosystem.

Share to...