Skip to content

تثبيت fnm على macOS

يتمتع fnm بطرق تثبيت متعددة على macOS. سيوضح هذا الدليل كيفية اختيار الأنسب لك.

طرق التثبيت

باستخدام Homebrew (موصى به)

Homebrew هو أكثر مدير الحزم شعبية على macOS:

bash
# Install fnm
brew install fnm

باستخدام سكريبت curl

لا يتطلب مدير حزم، قم بالتثبيت مباشرة:

bash
curl -fsSL https://fnm.vercel.app/install | bash

باستخدام MacPorts

إذا كنت تستخدم MacPorts:

bash
port install fnm

التنزيل اليدوي

  1. قم بزيارة صفحة إصدارات fnm
  2. قم بتنزيل fnm-macos.zip (Intel) أو fnm-macos-arm64.zip (Apple Silicon)
  3. قم باستخراج ونقل إلى دليل PATH:
bash
# Apple Silicon (M1/M2/M3)
unzip fnm-macos-arm64.zip
sudo mv fnm /usr/local/bin

# Intel Mac
unzip fnm-macos.zip
sudo mv fnm /usr/local/bin

تكوين الصدفة

تستخدم macOS Zsh افتراضياً، ولكن تدعم أيضاً Bash و Fish.

Zsh (افتراضي)

قم بتحرير ~/.zshrc:

bash
# Open configuration file
nano ~/.zshrc

# Add the following content
eval "$(fnm env --use-on-cd)"

أعد تحميل التكوين:

bash
source ~/.zshrc

Bash

قم بتحرير ~/.bashrc أو ~/.bash_profile:

bash
# Open configuration file
nano ~/.bash_profile

# Add the following content
eval "$(fnm env --use-on-cd)"

أعد تحميل التكوين:

bash
source ~/.bash_profile

Fish

قم بتحرير ~/.config/fish/config.fish:

fish
# Open configuration file
nano ~/.config/fish/config.fish

# Add the following content
fnm env --use-on-c | source

أعد تحميل التكوين:

fish
source ~/.config/fish/config.fish

اكتمال الصدفة

اكتمال Zsh

bash
# Add completion script
fnm completions --shell zsh > ~/.zsh/completion/_fnm

# Ensure fpath includes completion directory
# Add to ~/.zshrc
fpath=(~/.zsh/completion $fpath)

# Enable completion
autoload -U compinit && compinit

أو باستخدام oh-my-zsh:

bash
# Create completion directory
mkdir -p ~/.oh-my-zsh/completions

# Generate completion script
fnm completions --shell zsh > ~/.oh-my-zsh/completions/_fnm

اكتمال Bash

bash
# Add completion script
fnm completions --shell bash >> ~/.bashrc

# Reload
source ~/.bashrc

اكتمال Fish

bash
# Generate completion script
fnm completions --shell fish > ~/.config/fish/completions/fnm.fish

# Reload
source ~/.config/fish/config.fish

استخدام مرآة في الصين

في البر الرئيسي للصين، يُوصى بتكوين مرآة لتسريع التنزيلات:

bash
# Add to Shell configuration file
export FNM_NODE_DIST_MIRROR=https://npmmirror.com/mirrors/node

# Or specify during eval
eval "$(fnm env --use-on-cd --node-dist-mirror=https://npmmirror.com/mirrors/node)"

ملاحظات Apple Silicon (M1/M2/M3)

يدعم fnm بشكل كامل Apple Silicon:

  • يكشف تلقائياً عن بنية النظام
  • يثبت إصدار ARM64 الأصلي من Node.js
  • يدعم محاكاة x64 (عبر Rosetta 2)

تثبيت إصدار x64

إذا كنت تحتاج إلى إصدار x64 من Node.js:

bash
# Install x64 architecture Node.js
fnm install 20 --arch=x64

التحقق من التثبيت

bash
# Check fnm version
fnm --version

# Install Node.js
fnm install --lts

# Verify Node.js
node --version
npm --version

المشكلات الشائعة

الأمر غير موجود

إذا لم يتم العثور على أمر fnm بعد التثبيت:

bash
# Check fnm path
which fnm

# If installed via curl, ensure PATH includes
echo $PATH

# Manually add to PATH
export PATH="$HOME/.fnm:$PATH"

مشكلات الأذونات

إذا واجهت مشكلات أذونات:

bash
# Ensure directory has correct permissions
chmod +x ~/.fnm/fnm

تثبيت Homebrew لا يعمل

bash
# Re-link
brew unlink fnm && brew link fnm

# Check installation
brew list fnm

الخطوات التالية

بعد التثبيت، يمكنك:

روابط ذات صلة