AlmaLinux 9.2 Node.js 18 をインストールする手順

環境
# cat/etc/redhat-release
AlmaLinux release 9.2 (Turquoise Kodkod)

操作方法
1.有効になっている Node.js のバージョンを確認します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# dnf module list nodejs
メタデータの期限切れの最終確認: 0:18:51 前の 20230926131043秒 に実施しました。
AlmaLinux 9 - AppStream
Name Stream Profiles Summary
nodejs 18 common [d], development, minimal, s2i Javascript runtime
ヒント: [d]efault, [e]nabled, [x]disabled, [i]nstalled
# dnf module list nodejs メタデータの期限切れの最終確認: 0:18:51 前の 2023年09月26日 13時10分43秒 に実施しました。 AlmaLinux 9 - AppStream Name Stream Profiles Summary nodejs 18 common [d], development, minimal, s2i Javascript runtime ヒント: [d]efault, [e]nabled, [x]disabled, [i]nstalled
# dnf module list nodejs
メタデータの期限切れの最終確認: 0:18:51 前の 2023年09月26日 13時10分43秒 に実施しました。
AlmaLinux 9 - AppStream
Name                                Stream                              Profiles                                                           Summary
nodejs                              18                                  common [d], development, minimal, s2i                              Javascript runtime

ヒント: [d]efault, [e]nabled, [x]disabled, [i]nstalled

2.他バージョンが有効な場合は一旦リセットして有効バージョンを切り替えます。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# dnf module reset nodejs
# dnf module -y enable nodejs:18
# dnf module reset nodejs # dnf module -y enable nodejs:18
# dnf module reset nodejs
# dnf module -y enable nodejs:18

3.Node.js 18 を指定してインストールします。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# dnf module -y install nodejs:18/common
# dnf module -y install nodejs:18/common
# dnf module -y install nodejs:18/common

4.nodeのバージョンを確認します。

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

5.テストスクリプトを作成します。

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

6.動作確認

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# node test.js &
[1] 29012
# curl localhost:8080
Hello, study Node.js worold!
# kill 29012
# node test.js & [1] 29012 # curl localhost:8080 Hello, study Node.js worold! # kill 29012
# node test.js &
[1] 29012

# curl localhost:8080
Hello, study Node.js worold!

# kill 29012

 

AlmaLinux 9

Posted by arkgame