Skip to content

🗑️ GlobalRemove

Removes (uninstalls) an installed package from the Composer global environment.

When to use

Use this when a global CLI tool is no longer needed, or when you want to clean up the global environment. Equivalent to running composer global remove <package>.

Signature

go
func (c *Composer) GlobalRemove(packageName string) error

Parameters

ParameterTypeDescription
packageNamestringThe name of the package to remove from the global environment, e.g. psy/psysh

Return value

error: Returns the corresponding error message when an error occurs during execution (e.g. the package is not installed); nil on success.

Example

go
package main

import (
	"fmt"
	"log"

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

func main() {
	comp, err := composer.New(composer.DefaultOptions())
	if err != nil {
		log.Fatalf("Initialization failed: %v", err)
	}

	// Remove psysh from the global environment
	if err := comp.GlobalRemove("psy/psysh"); err != nil {
		log.Fatalf("Removal failed: %v", err)
	}

	fmt.Println("Removed psy/psysh from the global environment")
}

Advanced

  • To remove multiple packages at once, use GlobalRemoveMultiple.
  • To pass options such as --no-progress or --no-update, use the GlobalRemoveWithOptions variant.
  • After removal, call GlobalList to confirm the current global package list.
  • For the reverse operation (installing), see GlobalRequire.

Released under the MIT License