GitHub - nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
環境
2021-05-31 時点で最新の CentOS 8 Stream を利用した。
$ cat /etc/os-release
NAME="CentOS Stream"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Stream 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_SUPPORT_PRODUCT_VERSION="CentOS Stream"
$ uname -a
Linux localhost.localdomain 4.18.0-305.0.1.el8.x86_64 #1 SMP Fri May 28 11:04:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
手順
GitHub の README に記載の通りで OK.
インストールスクリプトをダウンロード & 実行する。
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 14926 100 14926 0 0 46937 0 --:--:-- --:--:-- --:--:-- 46937
=> Downloading nvm as script to '/home/vagrant/.nvm'
=> nvm source string already in /home/vagrant/.bashrc
=> bash_completion source string already in /home/vagrant/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
~/.nvm ディレクトリーに格納される。
$ ls -lA ~/.nvm
total 140
-rw-rw-r--. 1 vagrant vagrant 2201 May 31 07:08 bash_completion
-rwxrwxr-x. 1 vagrant vagrant 344 May 31 07:08 nvm-exec
-rw-rw-r--. 1 vagrant vagrant 134284 May 31 07:08 nvm.sh
~/.bashrc にも追記される。
$ tail ~/.bashrc
export PATH
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
再ログインする。
正体は関数。
$ which nvm | head
nvm ()
{
if [ $# -lt 1 ]; then
nvm --help;
return;
fi;
local DEFAULT_IFS;
DEFAULT_IFS=" $(nvm_echo t | command tr t \\t)
";
if [ "${-#*e}" != "$-" ]; then
ダウンロードした際のバージョンが出力される。
$ nvm --version
0.38.0
ヘルプも確認できる。
$ nvm --help | head
Node Version Manager (v0.38.0)
Note: <version> refers to any version-like string nvm understands. This includes:
- full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
- default (built-in) aliases: node, stable, unstable, iojs, system
- custom aliases you define with `nvm alias foo`
Any options that produce colorized output should respect the `--no-colors` option.
長期サポートバージョンの Node.js をインストールする。
$ nvm install --lts
Installing latest LTS version.
Downloading and installing node v14.17.0...
Downloading https://nodejs.org/dist/v14.17.0/node-v14.17.0-linux-x64.tar.xz...
######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v14.17.0 (npm v6.14.13)
Creating default alias: default -> lts/* (-> v14.17.0)
~/.nvm ディレクトリー以下にインストールされる。
$ which node npm npx
~/.nvm/versions/node/v14.17.0/bin/node
~/.nvm/versions/node/v14.17.0/bin/npm
~/.nvm/versions/node/v14.17.0/bin/npx
再ログイン不要で PATH も問題なく, バージョンを確認できる。
$ node --version
v14.17.0
npm や npx も同様。
$ npm --version
6.14.13
$ npx --version
6.14.13
どっとはらい。
↧