vfox Documentation

repository·main·Indexed 26 days ago

https://github.com/version-fox/vfox

vfox is a cross-platform version manager that allows users to install and switch between different runtime environments and libraries via a plugin system. It provides a CLI for managing SDKs, including commands to add plugins, install specific versions, and execute commands within isolated environments. It supports integration with multiple shells including Bash, ZSH, Fish, PowerShell, and Nushell.

Tokens
14.2K
Snippets
41
Records
98
Agent score
86%

What's inside vfox

  1. Overview of vfox version management

    main

    vfox is a cross-platform, extensible universal version manager for Windows (native) and Unix-like systems (Linux, macOS). It allows you to quickly install and switch between different development environments and runtime versions.

    Key features include:

    • Flexible version scopes: Manage versions at the Project-level, Session-level, or Global level.
    • Automatic switching: Automatically switches to the appropriate tool version when entering a project directory.
    • Configuration sharing: Saves tool version information in a .vfox.toml file, which can be shared across projects to ensure team consistency.
    • Compatibility: Supports existing version files like .node-version, .nvmrc, and .sdkmanrc.
    • Extensibility: Uses a simple plugin interface to support any language or tool.
  2. Understand the vfox plugin registry structure

    main

    The vfox plugin registry is a public repository used to collect and distribute plugins. Users can install plugins via vfox add <plugin-name>. The registry consists of two main directories:

    • plugins: Stores the manifest.json files for each plugin, named by the plugin's short name (e.g., nodejs.json).
    • sources: Stores the source information for each plugin manifest, also named by the plugin's short name (e.g., nodejs.json).

    The registry automatically retrieves the latest version information and verifies plugin availability every hour using the information in the sources directory.

  3. Clean Up vfox Data (Optional)

    main

    To permanently delete all installed SDK versions, plugins, configuration files, and the global .vfox.toml file, remove the vfox data directory:

    rm -rf ~/.version-fox

    Warning: This action is irreversible and will delete all SDK versions managed by vfox.

    rm -rf ~/.version-fox
  4. Remove vfox Shell Hooks

    main

    To prevent errors when starting your shell, you must remove the vfox activation commands from your shell configuration files. Follow the instructions for your specific shell:

    Bash

    Remove eval "$(vfox activate bash)" from ~/.bashrc and run:

    source ~/.bashrc

    ZSH

    Remove eval "$(vfox activate zsh)" from ~/.zshrc and run:

    source ~/.zshrc

    Fish

    Remove vfox activate fish | source from ~/.config/fish/config.fish and run:

    source ~/.config/fish/config.fish

    PowerShell

    1. Find your profile path by running $PROFILE.
    2. Remove Invoke-Expression "$(vfox activate pwsh)" from that file.
    3. Reload the profile:
    . $PROFILE
    1. Find the scripts path: clink info | findstr scripts
    2. Remove the clink_vfox.lua file from that directory.
    3. Restart Clink or Cmder.

    Nushell

    Open your Nushell config file (found via $nu.config-path) and remove the vfox activation line.

    eval "$(vfox activate bash)"
    eval "$(vfox activate zsh)"
    vfox activate fish | source
    Invoke-Expression "$(vfox activate pwsh)"
  5. Submit a plugin to the vfox registry

    main

    To publish a plugin to the public registry, follow these steps:

    1. Create the plugin: Follow the plugin creation guide.
    2. Maintain a manifest.json: Ensure your plugin has a manifest.json file describing its version and metadata. If using the vfox-plugin-template, this is generated automatically upon release.
    3. Create a source file: Create a JSON file in the sources/ directory of the registry repository using the plugin's short name (e.g., sources/nodejs.json).
    4. Configure the source file: Add the plugin's manifest URL and optional test configuration to the source file.
    5. Submit a PR: Submit a Pull Request to the vfox-plugins repository.

    Once the PR is merged, the plugin is added to the public registry and its status is checked hourly.

  6. Set up multi-user SDK sharing with vfox

    main

    In server environments, you can save disk space and simplify management by sharing SDK installations across multiple users. vfox achieves this by separating the Shared directory ($VFOX_HOME), which stores SDK files and plugins, from the User directory (~/.vfox), which stores personal configuration and version selections.

    1. Create a Shared Directory

    Use a group to manage access securely:

    # Create shared directory
    sudo mkdir -p /opt/vfox
    
    # Use group permissions
    sudo groupadd vfox
    sudo chgrp vfox /opt/vfox
    sudo chmod 2775 /opt/vfox
    
    # Add user to vfox group
    sudo usermod -a -G vfox username

    Windows

    Create a directory and grant full control to the 'Users' group:

    $vfoxPath = "D:\vfox"  # Modify to your desired path
    New-Item -ItemType Directory -Path $vfoxPath -Force
    
    $acl = Get-Acl $vfoxPath
    $rule = New-Object System.Security.AccessControl.FileSystemAccessRule(
        "Users",
        "FullControl",
        "ContainerInherit,ObjectInherit",
        "None",
        "Allow"
    )
    $acl.SetAccessRule($rule)
    Set-Acl $vfoxPath $acl

    2. Configure Each User

    Every user must set the VFOX_HOME environment variable to point to the shared directory.

    Bash (~/.bashrc):

    export VFOX_HOME=/opt/vfox

    ZSH (~/.zshrc):

    export VFOX_HOME=/opt/vfox

    Fish (~/.config/fish/config.fish):

    set -x VFOX_HOME /opt/vfox

    PowerShell:

    [System.Environment]::SetEnvironmentVariable('VFOX_HOME', 'D:\vfox', 'User')

    3. Install and Use SDKs

    Once configured, users can add plugins and install SDKs. The files will be stored in the shared $VFOX_HOME/cache directory.

    vfox add java
    vfox install java@21
    vfox use -g java@21
    # Linux/macOS (Recommended: Group Permissions)
    sudo mkdir -p /opt/vfox
    sudo groupadd vfox
    sudo chgrp vfox /opt/vfox
    sudo chmod 2775 /opt/vfox
    sudo usermod -a -G vfox username
  7. Use vfox in Docker, CI/CD, or non-interactive shells

    main

    For non-interactive environments like Docker build steps, CI jobs, or other non-interactive shells, do not rely on vfox activate as shell hooks are typically intended for interactive shells and may not trigger. Instead, use vfox exec to run commands immediately with the correct SDK environment.

    Use vfox use only when you want to persist version selection for Global, Project, or Session scope.

    vfox exec nodejs@24.14.0 -- npm install -g pnpm
    vfox exec nodejs@24.14.0 -- bash -lc 'node -v && npm -v'
  8. Plugin Directory Structure

    main

    A vfox plugin must follow a specific directory structure to be recognized and function correctly:

    • metadata.lua: Contains basic plugin information (name, version, etc.).
    • hooks/: Directory for hook functions. Each hook function must correspond to exactly one .lua file (e.g., hooks/available.lua).
    • lib/: Directory for dependent libraries. vfox automatically loads all .lua files in this directory. Files in other directories will not be loaded.
    • README.md: Plugin documentation.
    • LICENSE: Plugin license.

    To simplify development, you can use the vfox-plugin-template.

  9. Use the JSON Library in Lua

    main

    The json library (based on gopher-json) provides functions to encode Lua tables into JSON strings and decode JSON strings back into Lua tables. Use require("json") to load the library.

    local json = require("json")
    
    local obj = { "a", 1, "b", 2, "c", 3 }
    local jsonStr = json.encode(obj)
    local jsonObj = json.decode(jsonStr)
    
    -- Verify equality
    for i = 1, #obj do
        assert(obj[i] == jsonObj[i])
    end
  10. Manage runtimes with vfox CLI

    main

    Once vfox is installed and activated, you can manage language runtimes using the following workflow:

    1. Add a plugin for the language you want to use (e.g., nodejs):

      vfox add nodejs
    2. Install a specific version of the runtime:

      vfox install nodejs@21.5.0
    3. Switch to the installed version:

      vfox use nodejs@21.5.0
    4. Verify the version:

      node -v
    vfox add nodejs
    vfox install nodejs@21.5.0
    vfox use nodejs@21.5.0
  11. Hook vfox to your Shell

    main

    To enable automatic version switching and environment management, you must activate vfox in your shell configuration.

    Bash

    echo 'eval "$(vfox activate bash)"' >> ~/.bashrc
    source ~/.bashrc

    ZSH

    echo 'eval "$(vfox activate zsh)"' >> ~/.zshrc

    Fish

    echo 'vfox activate fish | source' >> ~/.config/fish/config.fish

    PowerShell

    Create the profile and add the activation command:

    if (-not (Test-Path -Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force }; Add-Content -Path $PROFILE -Value 'Invoke-Expression "$(vfox activate pwsh)"'

    Note: If you encounter script execution errors, run PowerShell as Administrator and execute Set-ExecutionPolicy -ExecutionPolicy RemoteSigned.

    Nushell

    vfox activate nushell $nu.default-config-dir | save --append $nu.config-path
    1. Find the scripts path: clink info | findstr scripts
    2. Copy clink_vfox.lua to the identified scripts directory.
    3. Restart Clink or Cmder.
    eval "$(vfox activate bash)"