Ubuntu, CentOS에 Node.js를 설치하는 방법은 무엇입니까?
다양한 환경에서 Node.js 설치하기: 상세 가이드
이 글에서는 Ubuntu 16.x/18.x 및 CentOS 7.x/8.x 시스템에서 바이너리 배포 또는 소스 코드를 사용하여 Node.js 11.x, 12.x, 14.x 버전을 설치하는 방법에 대해 자세히 설명합니다.
Node.js는 현대 웹 개발에서 빼놓을 수 없는 중요한 기술로 자리매김했습니다. 만약 여러분이 Node.js 개발을 배우기 시작하셨다면, 가장 먼저 해야 할 일 중 하나가 바로 Node.js를 설치하는 것입니다.
설치 방법은 다양하지만, 이 가이드에서는 간편하고 올바른 설치 과정을 제시하여 여러분의 개발 여정을 더욱 수월하게 만들어 드립니다.
이 가이드는 실제 테스트를 거친 방법이며, 디지털오션 서버를 기반으로 작성되었습니다. 이제 설치 과정을 시작해 보겠습니다.
Ubuntu 16.x 또는 18.x에 Node.js 설치
최신 버전의 Node.js는 기본 저장소에서 바로 사용할 수 없습니다. 하지만 걱정하지 마세요. NodeSource 배포를 이용하면 간단하게 설치할 수 있습니다.
- 먼저 서버에 루트 권한으로 로그인합니다.
- 다음 명령을 실행하여 원하는 Node.js 버전을 설치합니다.
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 저장소를 다운로드하고 설정합니다. 성공적으로 실행되면 다음과 유사한 출력이 표시될 것입니다.
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
- 이제 다음 명령을 사용하여 Node.js를 설치합니다.
apt-get install -y nodejs
설치가 완료되면, 다음 명령어로 버전을 확인할 수 있습니다.
[email protected]:~# nodejs -v v11.7.0 [email protected]:~#
위와 같이 설치된 Node.js 버전을 확인할 수 있습니다.
CentOS/RHEL 7.x 또는 8.x에 Node.js 설치
먼저 다음 명령을 사용하여 NodeSource 저장소를 설치합니다.
Node.js 11.x 설치:
curl -sL https://rpm.nodesource.com/setup_11.x | bash -
Node.js 12.x 설치:
curl -sL https://rpm.nodesource.com/setup_12.x | bash -
Node.js 14.x 설치:
curl -sL https://rpm.nodesource.com/setup_14.x | bash -
저장소 추가 후 다음 명령으로 Node.js를 설치합니다.
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] ~]#
설치가 성공적으로 완료되면 다음 명령으로 버전을 확인할 수 있습니다.
[[email protected] ~]# node -v v11.7.0 [[email protected] ~]#
위 방법은 Fedora 29 이상 버전에서도 동일하게 작동합니다.
소스 코드에서 Node.js 설치
만약 인터넷 연결이 제한된 DMZ 환경에 있다면, 소스 코드를 빌드하여 Node.js를 설치할 수 있습니다. 바이너리 배포보다는 조금 복잡하지만, 충분히 가능한 방법입니다.
- Ubuntu 또는 CentOS 서버에 로그인합니다.
- 여기에서 최신 또는 원하는 버전의 Node.js 소스 코드를 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 스크립트를 실행합니다.
./configure
- 오류가 없는지 확인한 후 다음 명령을 실행합니다.
make make install
빌드 및 설치 과정은 다소 시간이 걸릴 수 있습니다. 완료 후 다음 명령으로 설치된 버전을 확인할 수 있습니다.
[email protected]:~# node --version v11.7.0 [email protected]:~#
이처럼 Node.js 설치는 매우 간단합니다.
이제 전문 프로그래머가 되기 위한 여정을 Node.js 프레임워크 탐색과 함께 시작해 보세요.