Skip to content

⬇️ InstallComposerVersion

Downloads and installs a specific version of the Composer phar.

When to Use

Use this when you want to bypass the Installer instance and install a specific version (e.g. 2.5.1, preview) directly as a package-level function. 📚

Signature

go
func InstallComposerVersion(version string, installPath string, useSudo bool) error

Parameters

ParameterTypeDescription
versionstringVersion identifier: "1", "2", "latest", "preview", "stable", or a specific version like "2.5.1"
installPathstringInstall directory; the phar and wrapper script will be written here
useSudoboolWhether to use sudo for writing and permission changes

Return Value

  • error: Returns an ErrDownloadFailed wrapped error on download failure; returns the corresponding error on write failure. ⚠️

Example

go
package main

import (
	"fmt"
	"log"

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

func main() {
	if err := installer.InstallComposerVersion("2.5.1", "/usr/local/bin", true); err != nil {
		log.Fatalf("installation failed: %v", err)
	}
	fmt.Println("Composer 2.5.1 installed")
}

Advanced

  • Download URLs for version aliases: 1composer-1.phar; 2/latest/stablecomposer.phar; previewcomposer-preview.phar; specific versions go through download/{version}/composer.phar. 🌐
  • Automatically creates an executable wrapper script (a shell script on Unix, a .bat on Windows). 🛠️
  • The instance method InstallVersion wraps this function; path and sudo are taken from Config. 🔗
  • This method does not check for PHP; ensure PHP is installed before calling it. 🚫

Released under the MIT License