Ubuntu 22.04 Node.js の バージョン管理ツール [n] コマンドをインストールする
環境
Ubuntu 22.04.1 LTS
node v12.22.9
操作方法
1.[n] コマンドをインストールして、Node.js をアップグレードします
# npm install -g n
# npm install -g n
# npm install -g n
2. [stable] バージョンを確認します
# n --stable
18.12.0
# n --stable
18.12.0
# n --stable 18.12.0
3. [latest] バージョンを確認します
# n --latest
19.0.0
# n --latest
19.0.0
# n --latest 19.0.0
4.[latest] バージョンをインストールします
# n latest
installing : node-v19.0.0
mkdir : /usr/local/n/versions/node/19.0.0
fetch : https://nodejs.org/dist/v19.0.0/node-v19.0.0-linux-x64.tar.xz
copying : node/19.0.0
installed : v19.0.0 (with npm 8.19.2)
Note: the node command changed location and the old location may be remembered in your current shell.
old : /usr/bin/node
new : /usr/local/bin/node
If "node --version" shows the old version then start a new shell, or reset the location hash with:
hash -r (for bash, zsh, ash, dash, and ksh)
rehash (for csh and tcsh)
# n latest
installing : node-v19.0.0
mkdir : /usr/local/n/versions/node/19.0.0
fetch : https://nodejs.org/dist/v19.0.0/node-v19.0.0-linux-x64.tar.xz
copying : node/19.0.0
installed : v19.0.0 (with npm 8.19.2)
Note: the node command changed location and the old location may be remembered in your current shell.
old : /usr/bin/node
new : /usr/local/bin/node
If "node --version" shows the old version then start a new shell, or reset the location hash with:
hash -r (for bash, zsh, ash, dash, and ksh)
rehash (for csh and tcsh)
# n latest installing : node-v19.0.0 mkdir : /usr/local/n/versions/node/19.0.0 fetch : https://nodejs.org/dist/v19.0.0/node-v19.0.0-linux-x64.tar.xz copying : node/19.0.0 installed : v19.0.0 (with npm 8.19.2) Note: the node command changed location and the old location may be remembered in your current shell. old : /usr/bin/node new : /usr/local/bin/node If "node --version" shows the old version then start a new shell, or reset the location hash with: hash -r (for bash, zsh, ash, dash, and ksh) rehash (for csh and tcsh)
5.インストール済みバージョンを確認します
# n ls
node/19.0.0
# n ls
node/19.0.0
# n ls node/19.0.0
6.バージョンを切り替えます
# n node/19.0.0
copying : node/19.0.0
installed : v19.0.0 (with npm 8.19.2)
# n node/19.0.0
copying : node/19.0.0
installed : v19.0.0 (with npm 8.19.2)
# n node/19.0.0 copying : node/19.0.0 installed : v19.0.0 (with npm 8.19.2)
nodeバージョンを確認します
# node -v
v19.0.0
# node -v
v19.0.0
# node -v v19.0.0