Ubuntu 22.04にNode.js 12 をインストールする

環境

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Ubuntu 22.04.1 LTS
node v12.22.9
npm 8.5.1
Ubuntu 22.04.1 LTS node v12.22.9 npm 8.5.1
Ubuntu 22.04.1 LTS
node v12.22.9
npm 8.5.1

操作方法
1.Node.js 12 をインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# apt -y install nodejs npm
# apt -y install nodejs npm
# apt -y install nodejs npm

2.バージョンを確認します

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

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

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

4.動作確認
# node nodetest.js &
[1] 54120
# curl localhost:8080
Hello worl, This is the Node.js Simple Web Server!

Ubuntu 22.04

Posted by arkgame