Skip to content

👤 EnableSuperuser

Allows Composer to be run as root. Equivalent to setting COMPOSER_ALLOW_SUPERUSER=1.

When to use

In Docker containers or CI environments that run as root, Composer refuses root execution by default and emits a warning; calling this method suppresses the warning and allows execution.

Signature

go
func EnableSuperuser() error

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
Single return valueerrorReturned on failure (usually nil)

Example

go
package main

import (
	"fmt"
	"log"

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

func main() {
	if err := composer.EnableSuperuser(); err != nil {
		log.Fatalf("failed to enable superuser: %v", err)
	}
	fmt.Println("Running Composer as root is now allowed")
}

Advanced

  • To turn this off, use DisableSuperuser() (located in environment.go).
  • Under the hood this function sets EnvComposerAllowSuperuser; it can also be done via SetEnvVariable.
  • Security recommendation: only enable this in trusted containers/CI; in production, prefer running Composer as a non-root user.

Released under the MIT License