Skip to content

🎯 InstallVersion

Installs a specific version of Composer.

When to Use

Use this when you need to install a particular version rather than the latest (e.g. pinning to Composer 1.x, installing the preview version, or installing exactly 2.5.1). 📚

Signature

go
func (i *Installer) InstallVersion(version string) error

Parameters

ParameterTypeDescription
versionstringVersion identifier; can be "1", "2", "latest", "preview", "stable", or a specific version like "2.5.1"

Return Value

  • error: nil on success; ErrPHPNotFound when PHP is missing; returns a wrapped error on download or write failure. ⚠️

Example

go
package main

import (
	"fmt"
	"log"

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

func main() {
	i := installer.DefaultInstaller()
	// Install Composer 2.x
	if err := i.InstallVersion("2"); err != nil {
		log.Fatalf("installation failed: %v", err)
	}
	// Install a specific version
	if err := i.InstallVersion("2.5.1"); err != nil {
		log.Fatalf("installation failed: %v", err)
	}
	fmt.Println("specified version installed")
}

Advanced

  • Internally calls the package-level function InstallComposerVersion; the install path is taken from Config.InstallPath and whether to use sudo from Config.UseSudo. 🔧
  • For default installation without a version, use Install. 📦
  • This method requires PHP to be present and will not auto-install PHP (unlike Install). 🚫

Released under the MIT License