There are several methods to install the Node.js environment on CentOS:
-
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.
-
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 as14.x
,15.x
, etc. -
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 as14.17.0
.
Check the installed versions after running the installation commands:
|
|
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.