久し振りに EC2 で nodejs を実行させたい要望が出てきました。
過去に newman を動かすために node のバージョンアップを行ってから数年。

その時にインストールした NodeJS12 のサポートも終わり、NodeJS14 も 1 年を切りました。
(2022 年 6 月現在)
今回は新規インストールということで最新の NodeJS18 をセットアップしてみます。
AmazonLinux2
NodeJS はデフォルトではインストールされていないので yum で検索してみます。
1 | $ yum search nodejs |
AmazonLunux2 には NodeJS のパッケージが準備されていますね。
nodejs.x86_64 : JavaScript runtime
肝心なのは NodeJS のバージョン。
早速、確認してみましょう。
1 | $ yum info nodejs |
どうやら 16.15.0 のパッケージがインストール対象のようですね。
1 2 3 4 5 6 7 8 9 10 11 | Available Packages Name : nodejs Arch : x86_64 Epoch : 1 Version : 16.15.0 Release : 3.el7 Size : 100 k Repo : epel/x86_64 Summary : JavaScript runtime URL : http://nodejs.org/ License : MIT and ASL 2.0 and ISC and BSD |
NodeJS18のインストール
残念ながら 16.15.0 ということで最新バージョンではありません。
ということで、18.x 系を使うとしたら rpm からですね。
1 | $ curl -fsSL https://rpm.nodesource.com/setup_18.x | bash - |
インストール対象のパッケージは変わったでしょうか。
18.4.0 ってことで、つい最近リリースされたバージョンがターゲットとなりました。
1 2 3 4 5 6 7 8 9 10 11 12 13 | $ yum info nodejs Available Packages Name : nodejs Arch : x86_64 Epoch : 2 Version : 18.4.0 Release : 1nodesource Size : 33 M Repo : nodesource/x86_64 Summary : JavaScript runtime URL : http://nodejs.org License : MIT and ASL 2.0 and ISC and BSD |
ではインストールします。
1 | $ yum install nodejs |
おやっ、エラーが出ましたね。
AmazonLinux2 固有の問題でしょうか。
1 2 3 4 5 6 7 8 9 10 11 12 | Resolving Dependencies --> Running transaction check ---> Package nodejs.x86_64 2:18.4.0-1nodesource will be installed --> Processing Dependency: libc.so.6(GLIBC_2.28)(64bit) for package: 2:nodejs-18.4.0-1nodesource.x86_64 --> Processing Dependency: libm.so.6(GLIBC_2.27)(64bit) for package: 2:nodejs-18.4.0-1nodesource.x86_64 --> Finished Dependency Resolution Error: Package: 2:nodejs-18.4.0-1nodesource.x86_64 (nodesource) Requires: libm.so.6(GLIBC_2.27)(64bit) Error: Package: 2:nodejs-18.4.0-1nodesource.x86_64 (nodesource) Requires: libc.so.6(GLIBC_2.28)(64bit) You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest |
手元に AmazonLinux の EC2 があるので、そちらでも確認してみます。
AmazonLinux
既に新規インストールのサポートが終了している AmazonLinux ですが、運用中のサーバはまだ残っていたりしますよね。
古くからある AMI をベースにしているというところもありそうですし・・・。
AmazonLinux には yum の nodejs パッケージはないので、まずは rpm をセットアップします。
1 | $ curl -fsSL https://rpm.nodesource.com/setup_18.x | bash - |
node のセットアップに必要な gcc-c++ と make をインストールします。
1 | $ yum install gcc-c++ make |
上記の手順は、nodesource のドキュメントを参考にしています。
では、nodejs 本体のインストールをしてみましょう。
1 | $ yum install nodejs |
AmazonLinux2 と同じくエラーになりますね。
1 2 3 4 5 6 | Error: Package: 2:nodejs-18.4.0-1nodesource.x86_64 (nodesource) Requires: libm.so.6(GLIBC_2.27)(64bit) Error: Package: 2:nodejs-18.4.0-1nodesource.x86_64 (nodesource) Requires: libc.so.6(GLIBC_2.28)(64bit) You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest |
フォーラムで調べてみると、
You will not find those libraries in those versions for CentOS 7.
Even if you did, installing them would most likely break more than fix anything.
From a quick test, it seems the pub_18.x repository is just broken.
pub_17.x installs fine.
I would suggest to either use 17.x and/or file a bug on the NodeSource’s GitHub repo.
nodesource にある CentOS7 向けの nodejs18 の構成が壊れているとの情報が。
NodeJS16のインストール
ということで、AmazonLinux では一旦 16.x 系を入れておきます。
1 | $ curl -fsSL https://rpm.nodesource.com/setup_16.x | bash - |
18.x 系のインストールを試みたので、yum のキャッシュは念のため削除しておきますか。

1 2 3 4 5 6 7 8 | $ rm -rf /var/cache/yum/* $ yum info nodejs Name : nodejs Arch : x86_64 Epoch : 2 Version : 16.15.1 |
ではインストールします。
1 2 3 4 5 6 7 | $ yum install nodejs $ node --version v16.15.1 $ npm --version 8.11.0 |
まとめ
AmazonLinux2 へ NodeJS の 18.x 系をインストールする方法を紹介してきました。
残念ながら、yum のインストール中にエラーが発生したため、AmazonLinux では最新版のセットアップを断念し 16.x 系を。
AmazonLinux2 も同様だと思いますので、フォーラムに書かれていた問題が解決するのを待ちましょうか。
NodeJS に限らず、Kubernetes や Laravel など多くのアプリケーションのバージョンアップサイクルが短くなっています。
メジャーバージョンアップのリスクはありますが、早めの対応をしておきたいですね。
EKS や ECS など Docker 運用の場合はそこまで気にすることもないでしょうが。