コンテンツにスキップ

Pub

Dart package manager for managing dependencies and publishing packages - Essential commands and usage patterns.

Overview

Pub is a package manager used for dart package manager for managing dependencies and publishing packages. This cheat sheet covers the most commonly used commands and workflows.

Platform Support: Cross-platform Category: Development

Installation

Linux/Ubuntu

# Package manager installation
sudo apt update
sudo apt install pub

# Alternative installation methods
wget -O pub https://github.com/example/pub/releases/latest
chmod +x pub
sudo mv pub /usr/local/bin/

macOS

# Homebrew installation
brew install pub

# Manual installation
curl -L -o pub https://github.com/example/pub/releases/latest
chmod +x pub
sudo mv pub /usr/local/bin/

Windows

# Chocolatey installation
choco install pub

# Scoop installation
scoop install pub

# Manual installation
# Download from official website and add to PATH

Basic Commands

Command Description
pub --help Display help information
pub --version Show version information
pub init Initialize pub in current directory
pub status Check current status
pub list List available options/items

Common Operations

Basic Usage

# Start pub
pub start

# Stop pub
pub stop

# Restart pub
pub restart

# Check status
pub status

Configuration

# View configuration
pub config show

# Set configuration option
pub config set <key> <value>

# Reset configuration
pub config reset

Advanced Operations

# Verbose output
pub -v <command>

# Debug mode
pub --debug <command>

# Dry run (preview changes)
pub --dry-run <command>

# Force operation
pub --force <command>

File Operations

Command Description
pub create <file> Create new file
pub read <file> Read file contents
pub update <file> Update existing file
pub delete <file> Delete file
pub copy <src> <dst> Copy file
pub move <src> <dst> Move file

Network Operations

# Connect to remote host
pub connect <host>:<port>

# Listen on port
pub listen --port <port>

# Send data
pub send --data "<data>" --target <host>

# Receive data
pub receive --port <port>

Security Features

Authentication

# Login with credentials
pub login --user <username>

# Logout
pub logout

# Change password
pub passwd

# Generate API key
pub generate-key

Encryption

# Encrypt file
pub encrypt <file>

# Decrypt file
pub decrypt <file>

# Generate certificate
pub cert generate

# Verify signature
pub verify <file>

Troubleshooting

Common Issues

Issue: Command not found

# Check if installed
which pub

# Reinstall if necessary
sudo apt reinstall pub

Issue: Permission denied

# Run with sudo
sudo pub <command>

# Fix permissions
chmod +x /usr/local/bin/pub

Issue: Configuration errors

# Reset configuration
pub config reset

# Validate configuration
pub config validate

Debug Commands

Command Description
pub --debug Enable debug output
pub --verbose Verbose logging
pub test Run self-tests
pub doctor Check system health

Best Practices

Security

  • Always verify checksums when downloading
  • Use strong authentication methods
  • Regularly update to latest version
  • Follow principle of least privilege

Performance

  • Use appropriate buffer sizes
  • Monitor resource usage
  • Optimize configuration for your use case
  • Regular maintenance and cleanup

Maintenance

# Update pub
pub update

# Clean temporary files
pub clean

# Backup configuration
pub backup --config

# Restore from backup
pub restore --config <backup-file>

Integration

Scripting

#!/bin/bash
# Example script using pub

# Check if pub is available
if ! command -v pub &> /dev/null; then
    echo "pub is not installed"
    exit 1
fi

# Run pub with error handling
if pub <command>; then
    echo "Success"
else
    echo "Failed"
    exit 1
fi

API Integration

# Python example
import subprocess
import json

def run_pub(command):
    try:
        result = subprocess.run(['pub'] + command.split(),
                              capture_output=True, text=True)
        return result.stdout
    except Exception as e:
        print(f"Error: \\\\{e\\\\}")
        return None

Environment Variables

Variable Description Default
PUB_CONFIG Configuration file path ~/.pub/config
PUB_HOME Home directory ~/.pub
PUB_LOG_LEVEL Logging level INFO
PUB_TIMEOUT Operation timeout 30s

Configuration File

# ~/.pub/config.yaml
version: "1.0"
settings:
  debug: false
  timeout: 30
  log_level: "INFO"

network:
  host: "localhost"
  port: 8080
  ssl: true

security:
  auth_required: true
  encryption: "AES256"

Examples

Basic Workflow

# 1. Initialize
pub init

# 2. Configure
pub config set host example.com

# 3. Connect
pub connect

# 4. Perform operations
pub list
pub create example

# 5. Cleanup
pub disconnect

Advanced Workflow

# Automated deployment
pub deploy \
  --config production.yaml \
  --environment prod \
  --verbose \
  --timeout 300

# Monitoring
pub monitor \
  --interval 60 \
  --alert-threshold 80 \
  --log-file monitor.log

Resources

Official Documentation

Community

Tutorials


Last updated: 2025-07-05