CentOS 8.5にNode.js 10をインストールする

2021年12月21日

環境
OSバージョンの確認
# cat /etc/redhat-release
CentOS Linux release 8.5.2111

インストールの方法
1.有効になっている Node.js のバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# dnf module list nodejs
CentOS Linux 8 - AppStream
Name Stream Profiles Summary
nodejs 10 [d] common [d], development, minimal, s2i Javascript runtime
nodejs 12 common [d], development, minimal, s2i Javascript runtime
nodejs 14 common [d], development, minimal, s2i Javascript runtime
nodejs 16 [e] common [d] [i], development, minimal, s2i Javascript runtime
# dnf module list nodejs CentOS Linux 8 - AppStream Name Stream Profiles Summary nodejs 10 [d] common [d], development, minimal, s2i Javascript runtime nodejs 12 common [d], development, minimal, s2i Javascript runtime nodejs 14 common [d], development, minimal, s2i Javascript runtime nodejs 16 [e] common [d] [i], development, minimal, s2i Javascript runtime
# dnf module list nodejs
CentOS Linux 8 - AppStream
Name                   Stream                  Profiles                                                  Summary
nodejs                 10 [d]                  common [d], development, minimal, s2i                     Javascript runtime
nodejs                 12                      common [d], development, minimal, s2i                     Javascript runtime
nodejs                 14                      common [d], development, minimal, s2i                     Javascript runtime
nodejs                 16 [e]                  common [d] [i], development, minimal, s2i                 Javascript runtime

2. 他バージョンが有効な場合は一旦リセットします
# dnf module reset nodejs

3.有効バージョンを切り替えます
# dnf module enable nodejs:10

4.Node.js 10 を指定してインストールします
# dnf module -y install nodejs:10

nodeバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# node -v
v10.24.0
# node -v v10.24.0
# node -v
v10.24.0

5.動作確認
テストスクリプトを作成します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# cat > sample.js <<'EOF'
var http = require('http');
var server = http.createServer(function(req, res) {
res.write("Nodejs 10 test page!\n");
res.end();
}).listen(8080);
EOF
# cat > sample.js <<'EOF' var http = require('http'); var server = http.createServer(function(req, res) { res.write("Nodejs 10 test page!\n"); res.end(); }).listen(8080); EOF
#  cat > sample.js <<'EOF'
var http = require('http');
var server = http.createServer(function(req, res) {
   res.write("Nodejs 10 test page!\n");
   res.end();
 }).listen(8080);
 EOF

スクリプトを実行します
# node sample.js &
[1] 12265
# curl 127.0.0.1:8080
Nodejs 10 test page!

プロセスを停止します
# kill 11200

CentOS8

Posted by arkgame