javascript:nodejs

文書の過去の版を表示しています。


Node.js - サーバーサイド JavaScript 環境

日本ユーザグループ: Japan Node.js Association
本家: Node.js

Node.js はV8 JavaScript エンジン上に構築された JavaScript 実行環境の 1 つである。イベント化された入出力を扱うサーバーサイド JavaScript 環境であり、Web サーバなどのスケーラブルなネットワークプログラムの記述を意図している。ライアン・ダールによって 2009 年に作成され、ダールを雇用している Joyent の支援により成長している。
Node.js - Wikipedia より

本家: nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Node Version Manager(nvm) のインストールを行う。

$ curl -kL git.io/nodebrew | perl - setup

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:03 --:--:--     0
100 24634  100 24634    0     0   5131      0  0:00:04  0:00:04 --:--:-- 30041
Fetching nodebrew...
Installed nodebrew in $HOME/.nodebrew

========================================
Export a path to nodebrew:

export PATH=$HOME/.nodebrew/current/bin:$PATH
========================================

指示にしたがってパスを設定する。

$ vi ~/.bashrc

# User specific aliases and functions
export PATH=$HOME/.nodebrew/current/bin:$PATH

$ source ~/.bashrc

インストール可能なバージョンを調べる。

$ nodebrew ls-remote

〜省略〜
v12.7.0   v12.8.0   v12.8.1   v12.9.0   v12.9.1   v12.10.0    
〜省略〜

バージョンを指定してバイナリインストールする。

$ nodebrew install-binary v12.10.0

Fetching: https://nodejs.org/dist/v12.10.0/node-v12.10.0-linux-x64.tar.gz
######################################################################### 100.0%
Installed successfully

ビルドに必要なパッケージをインストールする。

$ sudo dnf install openssl-devel gcc-c++

nodebrew を使って node.js の最新バージョンをビルドしてインストールする場合。

$ nodebrew install latest
fetch: http://nodejs.org/dist/v5.4.1/node-v5.4.1.tar.gz
######################################################################## 100.0%
〜省略〜
installing /home/tomoyan/.nodebrew/node/v5.4.1/bin/node
installing /home/tomoyan/.nodebrew/node/v5.4.1/share/systemtap/tapset/node.stp
installing /home/tomoyan/.nodebrew/node/v5.4.1/share/doc/node/gdbinit
〜省略〜

インストールされているバージョンを確認する。

$ nodebrew ls

v12.10.0

current: none

利用するバージョンを指定します。

$ nodebrew use v12.10.0

use v12.10.0

アンインストールする場合。

$ nodebrew uninstall v7.7.2

v7.7.2 uninstalled

動作確認を行います。

$ nodebrew use v12.10.0

use v12.10.0

$ node -v

v12.10.0

ソースコード: nvm-windows

Scoop によるインストール。

nvm (Node Version Manager) をインストールする。
※ここでインストールされる nvmnvm-windows である。Linux の nvm とはオプションなどが異なる。

$ scoop install nvm

Installing 'nvm' (1.1.9) [64bit]
nvm-noinstall.zip (3.6 MB) [==================================================================================] 100%
Checking hash of nvm-noinstall.zip ... ok.
Extracting nvm-noinstall.zip ... done.
Running pre_install script...
Linking ~\scoop\apps\nvm\current => ~\scoop\apps\nvm\1.1.9
Creating shim for 'nvm'.
Persisting nodejs
Persisting elevate.cmd
Persisting elevate.vbs
Persisting settings.txt
'nvm' (1.1.9) was installed successfully!
Notes
-----
You'll need to restart powershell/cmd to have it reload Environment Variables so nvm will work correctly

$ nvm version

1.1.9

※Windows の nvm では、バージョン確認は version オプションである。

$ nvm


Running version 1.1.9.

Usage:

  nvm arch                     : Show if node is running in 32 or 64 bit mode.
  nvm current                  : Display active version.
  nvm install  [arch] : The version can be a specific version, "latest" for the latest current version, or "lts" for the
                                 most recent LTS version. Optionally specify whether to install the 32 or 64 bit version (defaults
                                 to system arch). Set [arch] to "all" to install 32 AND 64 bit versions.
                                 Add --insecure to the end of this command to bypass SSL validation of the remote download server.
  nvm list [available]         : List the node.js installations. Type "available" at the end to see what can be installed. Aliased as ls.
  nvm on                       : Enable node.js version management.
  nvm off                      : Disable node.js version management.
  nvm proxy [url]              : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.
                                 Set [url] to "none" to remove the proxy.
  nvm node_mirror [url]        : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url.
  nvm npm_mirror [url]         : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url.
  nvm uninstall       : The version must be a specific version.
  nvm use [version] [arch]     : Switch to use the specified version. Optionally use "latest", "lts", or "newest".
                                 "newest" is the latest installed version. Optionally specify 32/64bit architecture.
                                 nvm use  will continue using the selected version, but switch to 32/64 bit mode.
  nvm root [path]              : Set the directory where nvm should store different versions of node.js.
                                 If  is not set, the current root will be displayed.
  nvm version                  : Displays the current running version of nvm for Windows. Aliased as v.

$ nvm list available
</pre>


|   CURRENT    |     LTS      |  OLD STABLE  | OLD UNSTABLE |
|--------------|--------------|--------------|--------------|
|    18.6.0    |   16.16.0    |   0.12.18    |   0.11.16    |
|    18.5.0    |   16.15.1    |   0.12.17    |   0.11.15    |
|    18.4.0    |   16.15.0    |   0.12.16    |   0.11.14    |
|    18.3.0    |   16.14.2    |   0.12.15    |   0.11.13    |
|    18.2.0    |   16.14.1    |   0.12.14    |   0.11.12    |
|    18.1.0    |   16.14.0    |   0.12.13    |   0.11.11    |
|    18.0.0    |   16.13.2    |   0.12.12    |   0.11.10    |
|    17.9.1    |   16.13.1    |   0.12.11    |    0.11.9    |
|    17.9.0    |   16.13.0    |   0.12.10    |    0.11.8    |
|    17.8.0    |   14.20.0    |    0.12.9    |    0.11.7    |
|    17.7.2    |   14.19.3    |    0.12.8    |    0.11.6    |
|    17.7.1    |   14.19.2    |    0.12.7    |    0.11.5    |
|    17.7.0    |   14.19.1    |    0.12.6    |    0.11.4    |
|    17.6.0    |   14.19.0    |    0.12.5    |    0.11.3    |
|    17.5.0    |   14.18.3    |    0.12.4    |    0.11.2    |
|    17.4.0    |   14.18.2    |    0.12.3    |    0.11.1    |
|    17.3.1    |   14.18.1    |    0.12.2    |    0.11.0    |
|    17.3.0    |   14.18.0    |    0.12.1    |    0.9.12    |
|    17.2.0    |   14.17.6    |    0.12.0    |    0.9.11    |
|    17.1.0    |   14.17.5    |   0.10.48    |    0.9.10    |

This is a partial list. For a complete list, visit https://nodejs.org/en/download/releases

nvm install <version> [arch] arch=32 or 64 or all

$ nvm install 14.17.5 64

Downloading node.js version 14.17.5 (64-bit)...
Complete
Creating C:\Users\tomoyan\scoop\persist\nvm\nodejs\temp

Downloading npm version 6.14.14... Complete
Installing npm v6.14.14...

Installation complete. If you want to use this version, type

nvm use 14.17.5

$ nvm use 14.17.5 64

Now using node v14.17.5 (64-bit)

$ node --version

v14.15.1

ERROR open \settings.txt: The system cannot find the file specified. が発生する😱

ERROR open \settings.txt: · Issue #22 · coreybutler/nvm-windows

$ nvm use 14.17.5

ERROR open \settings.txt: The system cannot find the file specified.

環境変数 NVM_HOMENVM_SYMLINK が存在する場合は削除する。
cmdpowershell を完全に再起動するために、Windows Terminal も完全に終了して起動し直す。

exit status 1: ���̑��������s���邽�߂̏\���ȓ����������܂����B が発生する😵

Garbled error message when `nvm use` fails in Japanese environment. · Issue #740 · coreybutler/nvm-windows

$ nvm use 14.17.5

exit status 1: ���̑��������s���邽�߂̏\���ȓ����������܂����B

管理者実行しないと使えない機能がある。

$ sudo nvm use 14.17.5

Now using node v14.17.5 (64-bit)

  • javascript/nodejs.1658258524.txt.gz
  • 最終更新: 2022/07/20 04:22
  • by ともやん