Linux に fnm をインストール
fnm は Linux で複数のインストール方法があります。このガイドでは、さまざまな Linux ディストリビューションで fnm をインストールする方法を説明します。
インストール方法
curl スクリプトを使用(推奨)
最もシンプルなインストール方法:
bash
curl -fsSL https://fnm.vercel.app/install | bashインストール後、プロンプトに従って Shell をリロードするか、手動で PATH に追加:
bash
export PATH="$HOME/.fnm:$PATH"
eval "$(fnm env --use-on-cd)"Homebrew を使用
Linux に Homebrew がインストールされている場合:
bash
brew install fnm手動ダウンロード
- fnm リリースページ にアクセス
- アーキテクチャに合ったアーカイブをダウンロード:
bash
# x86_64
wget https://github.com/Schniz/fnm/releases/latest/download/fnm-linux.zip
# ARM64
wget https://github.com/Schniz/fnm/releases/latest/download/fnm-arm64.zip- 解凍してインストール:
bash
unzip fnm-linux.zip -d ~/.local/bin
chmod +x ~/.local/bin/fnmディストリビューション別インストールガイド
Ubuntu / Debian
bash
# 方法 1: curl スクリプトを使用
curl -fsSL https://fnm.vercel.app/install | bash
# 方法 2: 手動インストール
sudo apt update
sudo apt install -y unzip
wget https://github.com/Schniz/fnm/releases/latest/download/fnm-linux.zip
sudo unzip fnm-linux.zip -d /usr/local/bin
sudo chmod +x /usr/local/bin/fnmCentOS / RHEL / Fedora
bash
# 依存関係をインストール
sudo dnf install -y unzip # Fedora
# または
sudo yum install -y unzip # CentOS/RHEL
# curl スクリプトを使用
curl -fsSL https://fnm.vercel.app/install | bash
# または手動インストール
wget https://github.com/Schniz/fnm/releases/latest/download/fnm-linux.zip
sudo unzip fnm-linux.zip -d /usr/local/bin
sudo chmod +x /usr/local/bin/fnmArch Linux
bash
# AUR ヘルパーを使用
yay -S fnm-bin
# または AUR からビルド
git clone https://aur.archlinux.org/fnm-bin.git
cd fnm-bin
makepkg -siAlpine Linux
bash
# 依存関係をインストール
apk add bash curl unzip
# curl スクリプトを使用
curl -fsSL https://fnm.vercel.app/install | bash
# または手動インストール
wget https://github.com/Schniz/fnm/releases/latest/download/fnm-linux.zip
unzip fnm-linux.zip -d ~/.local/bin
chmod +x ~/.local/bin/fnmShell を設定
Bash
~/.bashrc を編集:
bash
echo 'eval "$(fnm env --use-on-cd)"' >> ~/.bashrc
source ~/.bashrcZsh
~/.zshrc を編集:
bash
echo 'eval "$(fnm env --use-on-cd)"' >> ~/.zshrc
source ~/.zshrcFish
~/.config/fish/config.fish を編集:
fish
echo 'fnm env --use-on-c | source' >> ~/.config/fish/config.fish
source ~/.config/fish/config.fishShell 補完
Bash 補完
bash
# bash-completion をインストール(未インストールの場合)
sudo apt install bash-completion # Debian/Ubuntu
sudo dnf install bash-completion # Fedora
# 補完スクリプトを追加
fnm completions --shell bash >> ~/.bashrc
source ~/.bashrcZsh 補完
bash
# 補完ディレクトリを作成
mkdir -p ~/.zsh/completions
# 補完スクリプトを生成
fnm completions --shell zsh > ~/.zsh/completions/_fnm
# ~/.zshrc に追加
fpath=(~/.zsh/completions $fpath)
autoload -U compinit && compinitFish 補完
bash
fnm completions --shell fish > ~/.config/fish/completions/fnm.fish中国のミラーを使用
中国本土では、ダウンロードを高速化するためにミラーの設定を推奨:
bash
# Shell 設定ファイルに追加
export FNM_NODE_DIST_MIRROR=https://npmmirror.com/mirrors/node
# または eval で指定
eval "$(fnm env --use-on-cd --node-dist-mirror=https://npmmirror.com/mirrors/node)"一般的なミラー:
| ミラーソース | URL |
|---|---|
| npmmirror | https://npmmirror.com/mirrors/node |
| 清華大学 | https://mirrors.tuna.tsinghua.edu.cn/nodejs-release |
| 華為雲 | https://mirrors.huaweicloud.com/nodejs |
インストールの確認
bash
# fnm バージョンを確認
fnm --version
# Node.js をインストール
fnm install --lts
# Node.js を確認
node --version
npm --versionよくある問題
コマンドが見つからない
bash
# fnm が PATH にあることを確認
which fnm
# 手動で PATH に追加
export PATH="$HOME/.fnm:$PATH"
# PATH を永続的に追加
echo 'export PATH="$HOME/.fnm:$PATH"' >> ~/.bashrc権限の問題
bash
# fnm に実行権限があることを確認
chmod +x ~/.fnm/fnm
# または
chmod +x /usr/local/bin/fnmダウンロードに失敗
bash
# ミラーを使用
export FNM_NODE_DIST_MIRROR=https://npmmirror.com/mirrors/node
fnm install --lts次のステップ
インストール後、以下を実行できます:
- Node.js をインストール - fnm を使用して Node.js をインストール
- コマンドリファレンス - 利用可能なすべてのコマンドを学ぶ
- バージョン管理 - バージョン管理を学ぶ
関連リンク
- fnm をインストール - 一般的なインストールガイド
- Windows インストール - Windows インストールガイド
- macOS インストール - macOS インストールガイド
- Ubuntu アンインストール - Ubuntu アンインストールガイド