Standard library / os

os.Unsetenv()

Removes a key from the process environment. An absent key is not an error. Example intended for Linux/AMD64 with Go 1.23.2 in a disposable working directory; other platforms may differ. Expected stdout: 'false\n'.

Formal Syntax & Structure

go syntaxgo
func Unsetenv(key string) error

Parameters & Attributes

NameTypeDescription
keystringEnvironment variable name.

Return Value

error

Removes a key from the process environment.

Working Example

Example Snippetgo
package main
import (  "fmt"  "os")
func must(e error) {  if e != nil {    panic(e)  }}func main() {  must(os.Setenv("BYTEMIND_SAMPLE", "x"))  must(os.Unsetenv("BYTEMIND_SAMPLE"))  _, ok := os.LookupEnv("BYTEMIND_SAMPLE")  fmt.Println(ok)}
Go Reference