#!/bin/bash # Save the original working directory ORIGINAL_DIR="$(pwd)" # Function to detect the operating system detect_os() { if [[ "$OSTYPE" == "darwin"* ]]; then echo "macos" elif [[ -f /etc/os-release ]]; then . /etc/os-release echo "$ID" else echo "unknown" fi } # Install fnm (Fast Node Manager) if it is not already installed if command -v fnm &> /dev/null; then echo -e "fnm is already installed\n" fnm --version else echo -e "Installing fnm (Fast Node Manager)\n" os=$(detect_os) case $os in macos) # Try homebrew first on macOS if command -v brew &> /dev/null; then echo "Installing fnm via Homebrew..." brew install fnm else echo "Installing fnm via official installer..." curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash fi ;; ubuntu|debian) # Use the official installer for Linux echo "Installing fnm via official installer..." curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash ;; fedora|centos|rhel) # Use the official installer for RHEL-based distros echo "Installing fnm via official installer..." curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash ;; arch|manjaro) # Use the official installer for Arch-based distros echo "Installing fnm via official installer..." curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash ;; *) echo "Using official installer for unknown OS..." curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash ;; esac # Load fnm for the remainder of this script export PATH="$HOME/.local/share/fnm:$PATH" eval "$(fnm env --use-on-cd)" fi # OPTIONAL: Install the latest LTS version of Node.js # Uncomment the following lines if you would like to automatically install it # echo "Installing latest LTS Node.js version..." # fnm install --lts # fnm use lts-latest # fnm default lts-latest # Apply the fnm zsh configuration patch (downloads zshrc/fnm.zsh to ~/.config/zshrc/fnm.zsh) curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s fnm echo -e "\nfnm installation completed!" echo -e "To start using fnm, restart your terminal or run: source ~/.zshrc" echo -e "\nUseful fnm commands:" echo -e " fnm install --lts # Install latest LTS Node.js" echo -e " fnm install 18 # Install Node.js v18" echo -e " fnm use 18 # Use Node.js v18" echo -e " fnm default 18 # Set Node.js v18 as default" echo -e " fnm list # List installed versions" echo -e " fnm list-remote # List available versions" # Restore original working directory cd "$ORIGINAL_DIR"