XserverにNode.jsはインストールできないと思っていたのですが、インストールできるらしいので他のサイトを参考にしながらやってみました。コマンドとログをメモしておきます。OSはWindows10です。
今回はnodebrewを使います。Node.jsのバージョン管理ツールです。nodebrewを使えば、1つのマシンの中でNode.jsをバージョンを切り替えて使うことができます。
# nodebrewのインストール(ダウンロードとセットアップ)
$ wget git.io/nodebrew
--2021-10-29 10:12:43-- http://git.io/nodebrew
(長いので割愛)
2021-10-29 10:12:45 (157 MB/s) - `nodebrew` へ保存完了 [24696/24696]
$ perl nodebrew setup
Fetching nodebrew...
Installed nodebrew in $HOME/.nodebrew
========================================
Export a path to nodebrew:
export PATH=$HOME/.nodebrew/current/bin:$PATH
========================================
# nodebrewのパスを通す
$echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bashrc
# 設定の読み込み(設定の反映)
$ source ~/.bashrc
# nodebrewのインストール確認
$ nodebrew -v
nodebrew 1.1.0
Usage:
nodebrew help Show this message
nodebrew install Download and install (from binary)
nodebrew compile Download and install (from source)
nodebrew install-binary Alias of `install` (For backward compatibility)
nodebrew uninstall Uninstall
nodebrew use Use
nodebrew list List installed versions
nodebrew ls Alias for `list`
nodebrew ls-remote List remote versions
nodebrew ls-all List remote and installed versions
nodebrew alias Set alias
nodebrew unalias Remove alias
nodebrew clean | all Remove source file
nodebrew selfupdate Update nodebrew
nodebrew migrate-package Install global NPM packages contained in to current version
nodebrew exec -- Execute using specified
Example:
# install
nodebrew install v8.9.4
# use a specific version number
nodebrew use v8.9.4
# 最新の安定板のバージョンのNode.jsをインストール
$ nodebrew install-binary stable
Fetching: https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.gz
(長いので割愛)
Installed successfully
# マシンにインストールされたNode.jsの確認
$ nodebrew ls
v16.13.0
current: none
# 利用するNode.jsのバージョンを指定
$ nodebrew use v16.13.0
use v16.13.0
# 現在利用する(できる)Node.jsのバージョン
$ node -v
v16.13.0