AlmaLinux8.4にnode.jsをインストールする

2021年10月3日

OSバージョンを確認
# cat /etc/redhat-release
AlmaLinux release 8.4 (Electric Cheetah)

1.標準のリポジトリを確認
# dnf info nodejs

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
利用可能なパッケージ
名前 : nodejs
エポック : 1
バージョン : 10.24.0
リリース : 1.module_el8.3.0+2047+b07ac28e
Arch : x86_64
サイズ : 8.8 M
ソース : nodejs-10.24.0-1.module_el8.3.0+2047+b07ac28e.src.rpm
リポジトリー : appstream
利用可能なパッケージ 名前 : nodejs エポック : 1 バージョン : 10.24.0 リリース : 1.module_el8.3.0+2047+b07ac28e Arch : x86_64 サイズ : 8.8 M ソース : nodejs-10.24.0-1.module_el8.3.0+2047+b07ac28e.src.rpm リポジトリー : appstream
利用可能なパッケージ
名前 : nodejs
エポック : 1
バージョン : 10.24.0
リリース : 1.module_el8.3.0+2047+b07ac28e
Arch : x86_64
サイズ : 8.8 M
ソース : nodejs-10.24.0-1.module_el8.3.0+2047+b07ac28e.src.rpm
リポジトリー : appstream

2.依存パッケージをインストール
# sudo dnf install gcc-c++ make

nodeをインストール
# sudo dnf install -y nodejs

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
中略
インストール済み:
nodejs-1:10.24.0-1.module_el8.3.0+2047+b07ac28e.x86_64
nodejs-full-i18n-1:10.24.0-1.module_el8.3.0+2047+b07ac28e.x86_64
npm-1:6.14.11-1.10.24.0.1.module_el8.3.0+2047+b07ac28e.x86_64
中略 インストール済み: nodejs-1:10.24.0-1.module_el8.3.0+2047+b07ac28e.x86_64 nodejs-full-i18n-1:10.24.0-1.module_el8.3.0+2047+b07ac28e.x86_64 npm-1:6.14.11-1.10.24.0.1.module_el8.3.0+2047+b07ac28e.x86_64
中略
インストール済み:
nodejs-1:10.24.0-1.module_el8.3.0+2047+b07ac28e.x86_64
nodejs-full-i18n-1:10.24.0-1.module_el8.3.0+2047+b07ac28e.x86_64
npm-1:6.14.11-1.10.24.0.1.module_el8.3.0+2047+b07ac28e.x86_64

3.n packageをインストール

# sudo npm install n -g

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
+ n@7.5.0
added 1 package from 2 contributors in 1.071s
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n + n@7.5.0 added 1 package from 2 contributors in 1.071s
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
+ n@7.5.0
added 1 package from 2 contributors in 1.071s

# n stable

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
installing : node-v14.18.0
mkdir : /usr/local/n/versions/node/14.18.0
fetch : https://nodejs.org/dist/v14.18.0/node-v14.18.0-linux-x64.tar.xz
installed : v14.18.0 (with npm 6.14.15)
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
To reset the command location hash either start a new shell, or execute PATH="$PATH"
installing : node-v14.18.0 mkdir : /usr/local/n/versions/node/14.18.0 fetch : https://nodejs.org/dist/v14.18.0/node-v14.18.0-linux-x64.tar.xz installed : v14.18.0 (with npm 6.14.15) 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 To reset the command location hash either start a new shell, or execute PATH="$PATH"
installing : node-v14.18.0
mkdir : /usr/local/n/versions/node/14.18.0
fetch : https://nodejs.org/dist/v14.18.0/node-v14.18.0-linux-x64.tar.xz
installed : v14.18.0 (with npm 6.14.15)

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
To reset the command location hash either start a new shell, or execute PATH="$PATH"

4.bash_profileを修正
追記
export N_PREFIX=$HOME/.n
export PATH=$N_PREFIX/bin:$PATH

5.古いバージョンnodejsをアンインストール
# sudo dnf remove -y nodejs npm

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
削除しました:
nodejs-1:10.24.0-1.module_el8.3.0+2047+b07ac28e.x86_64
nodejs-full-i18n-1:10.24.0-1.module_el8.3.0+2047+b07ac28e.x86_64
npm-1:6.14.11-1.10.24.0.1.module_el8.3.0+2047+b07ac28e.x86_64
略 削除しました: nodejs-1:10.24.0-1.module_el8.3.0+2047+b07ac28e.x86_64 nodejs-full-i18n-1:10.24.0-1.module_el8.3.0+2047+b07ac28e.x86_64 npm-1:6.14.11-1.10.24.0.1.module_el8.3.0+2047+b07ac28e.x86_64
略
削除しました:
nodejs-1:10.24.0-1.module_el8.3.0+2047+b07ac28e.x86_64
nodejs-full-i18n-1:10.24.0-1.module_el8.3.0+2047+b07ac28e.x86_64
npm-1:6.14.11-1.10.24.0.1.module_el8.3.0+2047+b07ac28e.x86_64

6.node.jsのバージョンを確認
# node -v
v14.18.0

7.npmのバージョンをアップデート

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# npm i -g npm
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
+ npm@7.24.1
added 70 packages from 27 contributors, removed 250 packages and updated 187 packages in 15.638s
# npm i -g npm /usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js + npm@7.24.1 added 70 packages from 27 contributors, removed 250 packages and updated 187 packages in 15.638s
# npm i -g npm
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
+ npm@7.24.1
added 70 packages from 27 contributors, removed 250 packages and updated 187 packages in 15.638s

8.npmのバージョンを確認
# npm -v
7.24.1

AlmaLinux

Posted by arkgame