Ubuntu 22.04 Node.js の バージョン管理ツール [n] コマンドをインストールする

環境
Ubuntu 22.04.1 LTS
node v12.22.9

操作方法
1.[n] コマンドをインストールして、Node.js をアップグレードします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# npm install -g n
# npm install -g n
# npm install -g n

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# n --stable
18.12.0
# n --stable 18.12.0
# n --stable
18.12.0

3. [latest] バージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# n --latest
19.0.0
# n --latest 19.0.0
# n --latest
19.0.0

4.[latest] バージョンをインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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.インストール済みバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# n ls
node/19.0.0
# n ls node/19.0.0
# n ls
node/19.0.0

6.バージョンを切り替えます

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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バージョンを確認します

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

 

Ubuntu 22.04

Posted by arkgame