Featured image of post Several Methods to Install the Node.js Environment (Node.js, npm) on CentOS

Several Methods to Install the Node.js Environment (Node.js, npm) on CentOS

There are several methods to install the Node.js environment on CentOS: use the EPEL repository to install: EPEL is Fed...

There are several methods to install the Node.js environment on CentOS:

  1. Using the EPEL Repository: EPEL is a software repository developed by the Fedora community, which provides additional packages for systems like Red Hat Enterprise Linux (RHEL) and CentOS. You can enable the EPEL repository and install Node.js with the following commands:

    1
    2
    3
    
    sudo yum install epel-release -y
    sudo yum install nodejs -y
    sudo yum install npm -y
    

    If the above commands do not install the latest version of Node.js, you can add the official Node.js repository to proceed with the installation.

  2. Using the Official Node.js Repository: The official Node.js repository offers the latest stable and LTS versions of Node.js. You can add the Node.js official repository and install Node.js with the following commands:

    1
    2
    
    curl -sL https://rpm.nodesource.com/setup_lts.x | sudo bash -
    sudo yum install nodejs
    

    If you need to install a different version of Node.js, you can replace lts in the above command with another version number, such as 14.x, 15.x, etc.

  3. Using nvm for Installation: nvm (Node Version Manager) is a version manager for Node.js that allows you to easily install and switch between different versions of Node.js. You can install nvm with the following command:

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

    After the installation is complete, execute the following command in the terminal to reload the shell:

    1
    
    source ~/.bashrc
    

    You can then use the following command to install the specified version of Node.js:

    1
    
    nvm install <version>
    

    Replace <version> with the desired Node.js version number, such as 14.17.0.

Check the installed versions after running the installation commands:

1
2
3
4
5
# npm --version
8.19.2

# node --version
v16.18.1

Several Methods to Install the Node.js Environment (Node.js, npm) on CentOS

These are three different methods to install the Node.js environment on CentOS. Each method has its own advantages and disadvantages, so you can choose the one that best suits your needs.

Licensed under CC BY-NC-SA 4.0