Home >Web Front-end >Front-end Q&A >yum install nodejs_configuration
CentOS is a widely used Linux operating system and occupies an important position in Linux-based server application software. On CentOS, Node.js is widely loved by developers as a reliable and high-performance JavaScript running environment. As one of the most commonly used package managers in CentOS systems, yum plays an indispensable role in installing and configuring Node.js.
This article will introduce the yum installation of Node.js on CentOS, as well as a series of basic configurations of Node.js, including setting up npm image source and version management.
Prerequisites
Before installing Node.js, you need to ensure that the CentOS system has some necessary software packages and tools:
With these basic software, we can start configuring and using Node.js.
Step 1: Install the node source
First, you need to log in to the system as a super user (root), and then execute the following command:
curl -sL https://rpm .nodesource.com/setup_14.x | bash -
This command will download the latest node js source file through the URL "https://rpm.nodesource.com/setup_14.x" and install it to in the system.
Step 2: Install Node.js and NPM
After completing the configuration of the node source, make sure you are still in the terminal as root and enter the following command to install Node.js and NPM:
yum install nodejs
yum install npm
After Node.js and NPM are installed, you can perform basic configuration.
Step 3: Set NPM mirror source
NPM mirror source refers to changing the default server address used by the npm command line tool to the address of another server. Because npm uses foreign sources by default, downloading and using it in China will be affected by network speed limits and instability. Therefore, in order to speed up the installation and update of dependencies, it is necessary to change the default source of npm to a domestic mirror source.
You can use the following command to change the default source of npm:
npm config set registry https://registry.npm.taobao.org
The above command will mirror npm The source is changed to the domestic Taobao image.
Step 4: Install Version Manager n
Version Manager n is a Node.js version management tool that allows you to install multiple versions of Node.js at the same time so that you can install different versions of Node.js at the same time. Different Node.js versions are used in the project.
You can use the following command to install n:
npm install -g n
Step 5: Use the version manager n to install the Node.js version
nBuilt-in After a series of commands, we can use n ls to view all currently installed versions.
n ls
You can use the following command to install the specified Node.js version:
n
For example, to install Node.js v8.9.0 version:
n 8.9.0
You can then use the n command to easily switch to the newly installed version.
Summary
It is very simple to install Node.js and NPM with yum on CentOS. Using yum to install and configure Node.js makes it easier for you to manage packages on your system and follow the standard package installation and uninstallation process to your system when you need to upgrade or uninstall Node.js.
By configuring the NPM source and using version manager n, you can download dependency packages and manage Node.js versions more conveniently, further improving development efficiency.
I hope this article can help developers who need to develop Node.js in CentOS environment.
The above is the detailed content of yum install nodejs_configuration. For more information, please follow other related articles on the PHP Chinese website!