Skip to content

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

手動ダウンロード

  1. fnm リリースページ にアクセス
  2. アーキテクチャに合ったアーカイブをダウンロード:
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
  1. 解凍してインストール:
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/fnm

CentOS / 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/fnm

Arch Linux

bash
# AUR ヘルパーを使用
yay -S fnm-bin

# または AUR からビルド
git clone https://aur.archlinux.org/fnm-bin.git
cd fnm-bin
makepkg -si

Alpine 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/fnm

Shell を設定

Bash

~/.bashrc を編集:

bash
echo 'eval "$(fnm env --use-on-cd)"' >> ~/.bashrc
source ~/.bashrc

Zsh

~/.zshrc を編集:

bash
echo 'eval "$(fnm env --use-on-cd)"' >> ~/.zshrc
source ~/.zshrc

Fish

~/.config/fish/config.fish を編集:

fish
echo 'fnm env --use-on-c | source' >> ~/.config/fish/config.fish
source ~/.config/fish/config.fish

Shell 補完

Bash 補完

bash
# bash-completion をインストール(未インストールの場合)
sudo apt install bash-completion  # Debian/Ubuntu
sudo dnf install bash-completion  # Fedora

# 補完スクリプトを追加
fnm completions --shell bash >> ~/.bashrc
source ~/.bashrc

Zsh 補完

bash
# 補完ディレクトリを作成
mkdir -p ~/.zsh/completions

# 補完スクリプトを生成
fnm completions --shell zsh > ~/.zsh/completions/_fnm

# ~/.zshrc に追加
fpath=(~/.zsh/completions $fpath)
autoload -U compinit && compinit

Fish 補完

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
npmmirrorhttps://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

次のステップ

インストール後、以下を実行できます:

関連リンク