Ubuntu, CentOS에 Node.js를 설치하는 방법은 무엇입니까?

바이너리 배포 또는 소스에서 Node.js 11.x, 12.x, 14.x를 Ubuntu 16.x/18.x, CentOS 7.x/8.x에 설치하는 절차입니다.

Node.js의 인기는 그 어느 때보다 빠르게 증가하고 있습니다. 최근에 시작했다면 Nodejs 개발 학습그런 다음 가장 먼저 해야 할 일 중 하나는 설치하는 것입니다.

기술적으로 설치하는 방법에는 여러 가지가 있지만 쉽고 올바른 프로세스를 따르면 삶이 훨씬 쉬워집니다.

다음은 제가 테스트한 디지털오션 섬기는 사람. 의가 시작하자.

우분투 16.x 또는 18.x

최신 버전의 Nodejs는 기본 리포지토리를 통해 사용할 수 없습니다. 하지만 걱정하지 마세요. 다음과 같이 NodeSource 배포를 사용할 수 있습니다.

  • 루트로 서버에 로그인
  • 다음을 실행

Node.js 11.x를 설치하려면

curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -

Node.js 12.x를 설치하려면

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

Node.js 14.x를 설치하려면

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

위에서 NodeSource Node.js 저장소를 다운로드하고 설치합니다. 위의 출력이 끝나면 다음과 같은 내용이 표시됩니다.

Reading package lists... Done

## Run `sudo apt-get install -y nodejs` to install Node.js 11.x and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
     echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn
  • 다음으로 다음 명령으로 nodejs를 설치해야 합니다.
apt-get install -y nodejs

몇 초가 걸리고 완료되면 완료됩니다. 버전을 확인할 수 있어야 합니다.

[email protected]:~# nodejs -v
v11.7.0
[email protected]:~#

그리고 보시다시피 11.7.0 버전이 설치되어 있습니다.

CentOS/RHEL 7.x 또는 8.x

먼저 다음 명령을 사용하여 NodeSource 리포지토리를 설치해야 합니다.

Nodejs 11.x 설치

curl -sL https://rpm.nodesource.com/setup_11.x | bash -

Nodejs 12.x 설치

curl -sL https://rpm.nodesource.com/setup_12.x | bash -

Nodejs 14.x 설치

curl -sL https://rpm.nodesource.com/setup_14.x | bash -

그런 다음 아래와 같이 Nodejs를 설치합니다.

yum install -y nodejs

CentOS 8.x를 사용하는 경우 DNF를 사용해 볼 수도 있습니다.

dnf install -y nodejs

몇 초가 걸리며 결국 아래와 같은 내용이 표시됩니다.

Running transaction
  Preparing        :                                                                                                                                                                1/1 
  Installing       : python3-setuptools-39.2.0-5.el8.noarch                                                                                                                         1/4 
  Installing       : python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64                                                                                                            2/4 
  Running scriptlet: python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64                                                                                                            2/4 
  Installing       : python3-pip-9.0.3-16.el8.noarch                                                                                                                                3/4 
  Running scriptlet: nodejs-2:14.9.0-1nodesource.x86_64                                                                                                                             4/4 
  Installing       : nodejs-2:14.9.0-1nodesource.x86_64                                                                                                                             4/4 
  Running scriptlet: nodejs-2:14.9.0-1nodesource.x86_64                                                                                                                             4/4 
  Verifying        : python3-pip-9.0.3-16.el8.noarch                                                                                                                                1/4 
  Verifying        : python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64                                                                                                            2/4 
  Verifying        : python3-setuptools-39.2.0-5.el8.noarch                                                                                                                         3/4 
  Verifying        : nodejs-2:14.9.0-1nodesource.x86_64                                                                                                                             4/4 

Installed:
  nodejs-2:14.9.0-1nodesource.x86_64       python3-pip-9.0.3-16.el8.noarch       python3-setuptools-39.2.0-5.el8.noarch       python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64      

Complete!
[[email protected] ~]#

이는 Node.js가 설치되었으며 -v 구문으로 확인할 수 있음을 의미합니다.

[[email protected] ~]# node -v
v11.7.0
[[email protected] ~]#

위의 지침은 Fedora 29 이상에서도 작동합니다.

  iOS에서 사진의 추억에 대한 알림을 끄는 방법

소스 코드에서 설치

인터넷에 연결할 수 없는 DMZ 환경에 있다면? 여전히 소스 코드를 빌드하여 설치할 수 있습니다. 절차는 바이너리 배포를 통해 위와 같이 쉽지는 않지만 가능합니다.

  • Ubuntu 또는 CentOS 서버에 로그인
  • 최신 또는 원하는 것을 다운로드하십시오. 여기 wget을 사용하여. 나는 최신 것을 시도하고 있습니다.
wget https://nodejs.org/dist/v11.7.0/node-v11.7.0.tar.gz
tar -xvf node-v11.7.0.tar.gz
  • 현재 작업 디렉토리에 생성된 새 폴더가 표시되어야 합니다.
drwxr-xr-x 9  502  501     4096 Jan 17 21:27 node-v11.7.0
  • 새로 만든 폴더로 이동
cd node-v11.7.0/

이제 소스에서 Node.js를 빌드할 시간입니다.

그러나 진행하기 전에 필수 구성 요소가 설치되어 있는지 확인하십시오.

Ubuntu를 사용하는 경우 아래의 필수 구성 요소를 설치합니다.

apt-get update
apt-get install gcc g++ clang make

그리고 CentOS의 경우

yum update
yum install gcc clang gcc-c++
./configure
  • 오류가 없는지 확인한 후 다음
make
make install

빌드하고 완료하는 데 시간이 좀 걸립니다. 아래를 실행하여 설치된 버전을 확인할 수 있습니다.

[email protected]:~# node --version
v11.7.0
[email protected]:~#

Nodejs 설치는 쉽습니다.

다음으로 Nodejs 프레임워크를 탐색하여 전문 프로그래머.