Skip to content

📦 Install

Installs Composer onto the system, automatically handling PHP dependencies and platform differences.

When to Use

Use this when you need to install Composer on the current machine (without specifying a version). The method first checks for PHP, then decides whether to use a package manager or direct download based on configuration, and finally delegates the actual installation to a platform-specific installer. 🚀

Signature

go
func (i *Installer) Install() error

Parameters

ParameterTypeDescription
NoneBehavior is determined by the Config passed when creating the Installer

Return Value

  • error: nil on success; ErrPHPNotFound when PHP is missing; ErrInsufficientRights on insufficient permissions; ErrUnsupportedPlatform for unsupported platforms. ⚠️

Example

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/installer"
)

func main() {
	i := installer.DefaultInstaller()
	if err := i.Install(); err != nil {
		log.Fatalf("installation failed: %v", err)
	}
	fmt.Println("Composer installed")
}

Advanced

  • If Config.AutoInstallPHP is true, it will attempt to auto-install PHP when missing. 🛠️
  • On Linux, if Config.PreferPackageManager is true, it will prefer installing via apt/dnf etc., falling back to direct download on failure. 🐧
  • To install a specific version, use InstallVersion; for progress callbacks and retries, use InstallWithProgress. ⚡

Released under the MIT License