Yum 安装 Node

4 min read Oct 03, 2024
Yum 安装 Node

How to Install Node.js Using Yum on Linux

Node.js is a powerful JavaScript runtime environment that allows you to build server-side applications, command-line tools, and more. If you're using a Linux distribution that utilizes the yum package manager, installing Node.js is a straightforward process.

What is Yum?

Yum (Yellowdog Updater, Modified) is a package management tool commonly found on Red Hat Enterprise Linux (RHEL) based distributions like CentOS, Fedora, and Amazon Linux. It simplifies the process of installing, updating, and removing software packages on your system.

Why Use Yum?

  • Easy Installation: Yum makes installing Node.js a breeze by automatically handling dependencies and ensuring a smooth installation process.
  • Version Management: Yum allows you to easily install specific versions of Node.js, giving you flexibility and control.
  • System Updates: Yum automatically updates your system, including Node.js, keeping you up-to-date with security patches and bug fixes.

Steps to Install Node.js using Yum:

  1. Enable the EPEL Repository:

    • The Extra Packages for Enterprise Linux (EPEL) repository contains a wider selection of software packages, including Node.js. To enable it, run the following command:

      sudo yum install epel-release
      
  2. Install Node.js:

    • Once the EPEL repository is enabled, you can install Node.js using the yum command:

      sudo yum install nodejs
      
  3. Verify the Installation:

    • To ensure that Node.js has been installed correctly, run the following commands:

      node -v
      npm -v
      
    • This should display the installed Node.js and npm versions.

Troubleshooting

  • If you encounter errors during the installation process:
    • Ensure that your internet connection is stable.
    • Check if the EPEL repository is enabled.
    • Try updating your yum package list: sudo yum update.
    • If the issue persists, consult the official documentation for your specific Linux distribution.

Installing a Specific Node.js Version

If you need a specific version of Node.js, you can use the nodejs package name followed by the version you desire. For example, to install Node.js version 16:

sudo yum install nodejs16

Note: The available Node.js versions may vary depending on the EPEL repository for your specific Linux distribution.

Alternative Methods

  • NVM (Node Version Manager): NVM provides a way to install and manage multiple Node.js versions on your system. This method offers greater flexibility but requires an additional installation step.
  • Source Code Compilation: While not recommended for most users, you can also download and compile the Node.js source code directly if you need a specific configuration.

Conclusion

Installing Node.js using yum on Linux distributions is a simple and efficient way to get started with this powerful runtime environment. With its ease of use and robust package management capabilities, yum makes the installation process hassle-free, allowing you to quickly start developing your Node.js applications.