How to Install and Use Gum in Linux to Build Interactive Shell Scripts

Writing shell scripts in Bash or Zsh to automate internal deployment pipelines, system configurations, or developer setup routines often results in plain, error-prone user experiences. Standard shell utilities like read and select offer primitive text input without arrow-key navigation, multi-select filtering, fuzzy search, or visual loading spinners. Gum, created by Charm, solves this by bringing glamorous, interactive terminal UI components to standard shell scripts.

Written in Go and designed for simple composition within Unix pipelines, Gum allows you to introduce multi-option menus, text inputs, password prompts, file pickers, confirmation modals, and animated progress spinners into any shell script with simple one-line CLI commands.

Why Use Gum in Shell Scripting?

Unlike massive terminal UI frameworks that require writing complex Go, Python, or Rust code, Gum was engineered specifically for bash and posix shell interoperability:

  • One-Line Terminal Widgets: Invoke interactive components (such as gum choose or gum input) directly inside shell scripts and capture user selections into standard environment variables.
  • Fuzzy Filter Selection: Allow users to filter through long lists of Git branches, Docker containers, or files using an integrated interactive fuzzy finder.
  • Beautiful Aesthetics: Renders vibrant colour borders, margins, alignments, and icons powered by Charm’s Lip Gloss styling library.
  • Non-Intrusive Integration: Easily drop Gum into existing scripts without changing your underlying shell logic or installing heavy runtime interpreters.

How to Install Gum Across Linux Distributions

Gum is distributed through official packaging repositories across mainstream Linux distributions.

Ubuntu, Debian, and Linux Mint

Add the Charm official APT repository and install the package:

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install -y gum

Fedora, Rocky Linux, and RHEL

Install via the Charm RPM repository:

echo '[charm]
name=Charm
baseurl=https://repo.charm.sh/yum/
enabled=1
gpgcheck=1
gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo
sudo dnf install -y gum

Arch Linux and Manjaro

Install directly from the official Pacman repositories:

sudo pacman -S gum

Core Gum Commands and Interactive Primitives

Gum provides several modular commands tailored for specific user input scenarios:

Command Interface Widget Common Automation Use Case
gum choose Interactive arrow-key list Selecting deployment environments (dev, staging, prod).
gum filter Fuzzy searchable menu Picking a Git branch or AWS profile from a large list.
gum input Single-line text prompt Gathering commit messages, usernames, or IP addresses.
gum write Multi-line text editor Composing detailed release notes or issue descriptions.
gum confirm Yes / No dialogue prompt Confirming destructive actions (e.g. database migrations).
gum spin Animated spinner graphic Masking long-running compile or package install tasks.
gum file Terminal file browser Selecting configuration files or media uploads.
gum style Border and text colouriser Formatting terminal banners, headers, and error boxes.

Practical Examples: Building Interactive Scripts

1. Creating an Interactive Selection Menu

Prompting a developer to pick an environment and capturing the result into a shell variable:

ENVIRONMENT=$(gum choose "Development" "Staging" "Production" --header="Select Deployment Target:")
echo "Deploying infrastructure to: $ENVIRONMENT"

2. Fuzzy Filtering Git Branches

Selecting and checking out a Git branch without typing long branch names:

BRANCH=$(git branch --format='%(refname:short)' | gum filter --placeholder="Find git branch...")
if [ -n "$BRANCH" ]; then
    git checkout "$BRANCH"
fi

3. Confirmation Modal for Destructive Operations

Prompting users before executing high-risk commands:

if gum confirm "Are you sure you want to drop the staging database?"; then
    echo "Executing database migration..."
else
    echo "Operation aborted by user."
    exit 1
fi

4. Masking Long Commands with Progress Spinners

Running a slow background build or update task behind an elegant animated spinner:

gum spin --spinner dot --title "Compiling binary assets..." -- sleep 3

Putting It All Together: A Complete Interactive Backup Script

Here is how several Gum primitives integrate into a cohesive, professional administrative script:

#!/usr/bin/env bash

# Display header banner
gum style --border normal --margin "1" --padding "1 2" --border-foreground 212 "PostgreSQL Database Backup Utility"

# Prompt for target database
DB_NAME=$(gum input --placeholder "Enter database name" --value "production_db")

# Prompt for backup format
FORMAT=$(gum choose "SQL Plaintext" "Custom Tarball" "Directory Archive")

# Confirm execution
if gum confirm "Begin backup of '$DB_NAME' using '$FORMAT' format?"; then
    gum spin --spinner line --title "Dumping database..." -- sleep 2
    gum style --foreground 82 "✔ Backup completed successfully!"
else
    gum style --foreground 196 "✖ Backup cancelled."
    exit 0
fi

By replacing brittle standard shell prompts with Gum, your automation scripts gain modern accessibility, visual clarity, and professional command-line polish.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.