Amazon Linux Nodejs Install with Epel

Amazon Linux에 Nodejs는 yum 인스톨이 되지 않는다.

이 부분을 해결하기 위해서 다음과 같이

sudo amazon-linux-extras install epel -y

리포지토리를 활성화 하거나

sudo yum-config-manager --enable epel

Config Manager를 사용해서 epel를 활성화 해줘야 한다.

sudo yum -y install nodejs

명령어를 통해서 nodejs를 install 할 수 있다.

Ansible을 통한 script는 다음과 같다.

---
- name: "epel repo add"
  become: yes
  shell: "amazon-linux-extras install epel -y"

- name: "install nodejs"
  become: yes
  yum:
    name: "nodejs"
    state: latest

 

최신버전 nodejs는?

Amazon Linux에서 nodejs 최신 버전을 사용하기 위해서는 다음 url을 참고 해야한다.

docs.aws.amazon.com/ko_kr/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html

 

자습서: Amazon EC2 인스턴스에서 Node.js 설정 - 용 AWS SDK JavaScript

노드 설치는 현재 EC2 세션에만 적용됩니다. EC2 인스턴스가 사라지면 노드를 다시 설치해야 합니다. 다음 단원에 설명된 대로 유지하려는 구성이 있는 경우 대안은 EC2 인스턴스의 AMI를 만드는 것

docs.aws.amazon.com

명령어 입력 순서는 다음과 같다.

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

. ~/.nvm/nvm.sh

nvm install node

[ec2-user@ip-172-31-23-35 ~]$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13226  100 13226    0     0   287k      0 --:--:-- --:--:-- --:--:--  287k
=> Downloading nvm as script to '/home/ec2-user/.nvm'

=> Appending nvm source string to /home/ec2-user/.bashrc
=> Appending bash_completion source string to /home/ec2-user/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
[ec2-user@ip-172-31-23-35 ~]$ . ~/.nvm/nvm.sh
[ec2-user@ip-172-31-23-35 ~]$ nvm install node
Downloading and installing node v15.8.0...
Downloading https://nodejs.org/dist/v15.8.0/node-v15.8.0-linux-x64.tar.xz...
#################################################################################################################################################################################### 100.0%Computing checksum with sha256sum
Checksums matched!
npm notice 
npm notice New patch version of npm available! 7.5.1 -> 7.5.4
npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.5.4
npm notice Run npm install -g npm@7.5.4 to update!
npm notice
Now using node v15.8.0 (npm v7.5.1)
Creating default alias: default -> node (-> v15.8.0)
[ec2-user@ip-172-31-23-35 ~]$ node
Welcome to Node.js v15.8.0.
Type ".help" for more information.
> exit
Uncaught ReferenceError: exit is not defined
> .exit
[ec2-user@ip-172-31-23-35 ~]$ npm

Usage: npm <command>

npm install        install all the dependencies in your project
npm install <foo>  add the <foo> dependency to your project
npm test           run this project's tests
npm run <foo>      run the script named <foo>
npm <command> -h   quick help on <command>
npm -l             display usage info for all commands
npm help <term>    search for help on <term>
npm help npm       more involved overview

All commands:

    access, adduser, audit, bin, bugs, cache, ci, completion,
    config, dedupe, deprecate, diff, dist-tag, docs, doctor,
    edit, exec, explain, explore, find-dupes, fund, get, help,
    hook, init, install, install-ci-test, install-test, link,
    ll, login, logout, ls, org, outdated, owner, pack, ping,
    prefix, profile, prune, publish, rebuild, repo, restart,
    root, run-script, search, set, set-script, shrinkwrap, star,
    stars, start, stop, team, test, token, uninstall, unpublish,
    unstar, update, version, view, whoami

Specify configs in the ini-formatted file:
    /home/ec2-user/.npmrc
or on the command line via: npm <command> --key=value

More configuration info: npm help config
Configuration fields: npm help 7 config

npm@7.5.1 /home/ec2-user/.nvm/versions/node/v15.8.0/lib/node_modules/npm

npm notice 
npm notice New patch version of npm available! 7.5.1 -> 7.5.4
npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.5.4
npm notice Run npm install -g npm@7.5.4 to update!
npm notice
[ec2-user@ip-172-31-23-35 ~]$ npm install pm2
npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)

added 203 packages, and audited 204 packages in 11s

10 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
[ec2-user@ip-172-31-23-35 ~]$ pm2 start index.js -f

                        -------------

__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
 _\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
  _\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
   _\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
    _\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
     _\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
      _\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
       _\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
        _\///______________\///______________\///__\///////////////__


                          Runtime Edition

        PM2 is a Production Process Manager for Node.js applications
                     with a built-in Load Balancer.

                Start and Daemonize any application:
                $ pm2 start app.js

                Load Balance 4 instances of api.js:
                $ pm2 start api.js -i 4

                Monitor in production:
                $ pm2 monitor

                Make pm2 auto-boot at server restart:
                $ pm2 startup

                To go further checkout:
                http://pm2.io/


                        -------------

[PM2] Spawning PM2 daemon with pm2_home=/home/ec2-user/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting /home/ec2-user/index.js in fork_mode (1 instance)
[PM2] Done.
┌─────┬──────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name     │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼──────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ index    │ default     │ N/A     │ fork    │ 10297    │ 0s     │ 0    │ online    │ 0%       │ 22.9mb   │ ec2-user │ disabled │
└─────┴──────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[ec2-user@ip-172-31-23-35 ~]$

curl을 사용하는등 인터넷에 있는 다른 것을 활용해서 해봤는데, 이 방법이 가장 정확했다.

728x90
반응형

'AWS' 카테고리의 다른 글

Cloud9 Ports 오픈 하기  (0) 2021.03.01
EC2 Volume Size Extension  (0) 2021.03.01
cloud 9 AWS Resources Tab  (0) 2021.02.27
AWS default VPC 만들기 & ssh 접근 오류  (0) 2021.02.13
AWS CLI EC2 사용법  (0) 2021.02.13