Skip to content

🗑️ Uninstall

Uninstalls Composer from the system.

When to Use

Use this when you need to remove the Composer executable and its .phar file. It first locates the current composer path, then deletes that path and the composer.phar in the same directory. 🧹

Signature

go
func (i *Installer) Uninstall() error

Parameters

ParameterTypeDescription
NoneBehavior is determined by Config.UseSudo for whether sudo is used to delete

Return Value

  • error: nil on success; returns a wrapped error when composer is not found; returns the corresponding error on deletion failure. ⚠️

Example

go
package main

import (
	"fmt"
	"log"

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

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

Advanced

  • If the file is in a directory that requires elevated permissions, set Config.UseSudo to true; otherwise the deletion will fail due to insufficient permissions. 🔒
  • You can use IsInstalled beforehand to confirm presence and avoid needless errors. ✅
  • Under the hood it calls the package-level function UninstallComposer, which also cleans up composer.phar. 🧩

Released under the MIT License