Deno Installation Guide

Deno is a free and open-source modern runtime for JavaScript and TypeScript built on V8 and Rust. It serves as a FOSS alternative to Node.js, providing built-in TypeScript support, security-first design, web-standard APIs, and modern development features without package.json or node_modules.

Development tools🟢 beginner11 min⏱️ 5-15 minutes

Deno is a free and open-source modern runtime for JavaScript and TypeScript built on V8 and Rust. It serves as a FOSS alternative to Node.js, providing built-in TypeScript support, security-first design, web-standard APIs, and modern development features without the need for package.json or node_modules. Deno offers a more secure and streamlined approach to server-side JavaScript development.

1. Prerequisites

Hardware Requirements

  • CPU: Modern 64-bit processor (x86_64 or ARM64)
  • RAM: 512MB minimum (1GB+ recommended)
  • Storage: 100MB for Deno binary, additional for projects
  • Network: Internet connection for module downloads
  • Software Requirements

  • Operating System: Linux, macOS, or Windows
  • Shell: Bash, Zsh, or PowerShell for installation scripts
  • Optional: Git for version control
  • Network Requirements

  • HTTPS: Access to deno.land and GitHub for modules
  • Ports: Application-specific (commonly 8000, 3000)
  • 2. Supported Operating Systems

    Deno officially supports:

  • RHEL 8/9 and derivatives (CentOS Stream, Rocky Linux, AlmaLinux)
  • Debian 11/12
  • Ubuntu 20.04 LTS / 22.04 LTS / 24.04 LTS
  • Arch Linux
  • Alpine Linux 3.18+
  • openSUSE Leap 15.5+ / Tumbleweed
  • Fedora 38+
  • macOS 10.15+ (Catalina and later)
  • Windows 10/11
  • 3. Installation

    #### Linux/macOS

    bash
    # Install Deno using official script
    curl -fsSL https://deno.land/install.sh | sh
    
    # Add to PATH (add to ~/.bashrc or ~/.zshrc)
    export DENO_INSTALL="$HOME/.deno"
    export PATH="$DENO_INSTALL/bin:$PATH"
    
    # Reload shell configuration
    source ~/.bashrc  # or ~/.zshrc
    
    # Verify installation
    deno --version

    #### Windows (PowerShell)

    powershell
    # Install using PowerShell script
    irm https://deno.land/install.ps1 | iex
    
    # Add to PATH (automatic with installer)
    # Verify installation
    deno --version

    Method 2: Package Managers

    #### RHEL/CentOS/Rocky Linux/AlmaLinux

    bash
    # Install via GitHub releases
    DENO_VERSION="v1.40.0"  # Check latest version
    curl -LO "https://github.com/denoland/deno/releases/download/${DENO_VERSION}/deno-x86_64-unknown-linux-gnu.zip"
    unzip deno-x86_64-unknown-linux-gnu.zip
    sudo mv deno /usr/local/bin/
    sudo chmod +x /usr/local/bin/deno
    
    # Verify installation
    deno --version

    #### Debian/Ubuntu

    bash
    # Method 1: Official script
    curl -fsSL https://deno.land/install.sh | sh
    
    # Method 2: Download binary directly
    wget -qO- https://github.com/denoland/deno/releases/latest/download/deno-x86_64-unknown-linux-gnu.zip | \
    sudo funzip > /usr/local/bin/deno
    sudo chmod +x /usr/local/bin/deno
    
    # Add to PATH
    echo 'export PATH="$HOME/.deno/bin:$PATH"' >> ~/.bashrc
    source ~/.bashrc

    #### Arch Linux

    bash
    # Install from official repositories
    sudo pacman -S deno
    
    # Or install from AUR (latest version)
    yay -S deno-bin
    
    # Verify installation
    deno --version

    #### Alpine Linux

    bash
    # Install from community repository
    apk add --no-cache deno
    
    # Or install manually
    wget https://github.com/denoland/deno/releases/latest/download/deno-x86_64-unknown-linux-gnu.zip
    unzip deno-x86_64-unknown-linux-gnu.zip
    mv deno /usr/local/bin/
    chmod +x /usr/local/bin/deno

    #### openSUSE

    bash
    # Install via zypper (if available)
    sudo zypper install deno
    
    # Or manual installation
    DENO_VERSION="v1.40.0"
    wget "https://github.com/denoland/deno/releases/download/${DENO_VERSION}/deno-x86_64-unknown-linux-gnu.zip"
    unzip deno-x86_64-unknown-linux-gnu.zip
    sudo mv deno /usr/local/bin/
    sudo chmod +x /usr/local/bin/deno

    #### macOS

    bash
    # Method 1: Homebrew
    brew install deno
    
    # Method 2: MacPorts
    sudo port install deno
    
    # Method 3: Official script
    curl -fsSL https://deno.land/install.sh | sh

    #### Windows

    powershell
    # Method 1: Winget
    winget install DenoLand.Deno
    
    # Method 2: Chocolatey
    choco install deno
    
    # Method 3: Scoop
    scoop install deno

    Method 3: Cargo (Rust Package Manager)

    bash
    # Install Rust if not already installed
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
    # Install Deno from source
    cargo install deno --locked
    
    # Verify installation
    deno --version

    4. Configuration

    Environment Configuration

    bash
    # Set Deno configuration directory
    export DENO_DIR="$HOME/.cache/deno"
    
    # Configure permissions for development
    export DENO_PERMISSIONS="--allow-net --allow-read --allow-write"
    
    # Set TypeScript configuration
    export DENO_TSCONFIG="./tsconfig.json"
    
    # Configure import map
    export DENO_IMPORT_MAP="./import_map.json"

    Project Configuration

    Create deno.json for project configuration:

    json
    {
      "compilerOptions": {
        "allowJs": true,
        "lib": ["deno.window"],
        "strict": true
      },
      "lint": {
        "rules": {
          "tags": ["recommended"]
        }
      },
      "fmt": {
        "files": {
          "include": ["src/"],
          "exclude": ["src/testdata/"]
        },
        "options": {
          "useTabs": false,
          "lineWidth": 80,
          "indentWidth": 2,
          "singleQuote": true
        }
      },
      "tasks": {
        "start": "deno run --allow-net --allow-read main.ts",
        "dev": "deno run --allow-net --allow-read --watch main.ts",
        "test": "deno test --allow-net --allow-read"
      },
      "imports": {
        "std/": "https://deno.land/std@0.208.0/",
        "oak": "https://deno.land/x/oak@v12.6.1/mod.ts"
      }
    }

    Import Map Configuration

    Create import_map.json:

    json
    {
      "imports": {
        "std/": "https://deno.land/std@0.208.0/",
        "oak": "https://deno.land/x/oak@v12.6.1/mod.ts",
        "postgres": "https://deno.land/x/postgres@v0.17.0/mod.ts",
        "redis": "https://deno.land/x/redis@v0.31.0/mod.ts"
      }
    }

    5. Service Management

    Systemd Service Configuration

    Create /etc/systemd/system/deno-app.service:

    ini
    [Unit]
    Description=Deno Application
    After=network.target
    
    [Service]
    Type=simple
    User=deno
    Group=deno
    WorkingDirectory=/opt/deno-app
    ExecStart=/usr/local/bin/deno run --allow-net --allow-read --allow-env main.ts
    Restart=always
    RestartSec=3
    Environment=DENO_DIR=/var/cache/deno
    Environment=PORT=8000
    
    [Install]
    WantedBy=multi-user.target
    bash
    # Create deno user
    sudo useradd -r -s /bin/false -d /opt/deno-app deno
    
    # Set permissions
    sudo chown -R deno:deno /opt/deno-app
    sudo mkdir -p /var/cache/deno
    sudo chown -R deno:deno /var/cache/deno
    
    # Enable and start service
    sudo systemctl daemon-reload
    sudo systemctl enable --now deno-app
    sudo systemctl status deno-app

    Development Server

    bash
    # Start development server with file watching
    deno run --allow-net --allow-read --watch main.ts
    
    # Start with specific permissions
    deno run --allow-net=:8000 --allow-read=./static main.ts
    
    # Start with all permissions (development only)
    deno run -A main.ts

    Process Management with PM2

    bash
    # Install PM2 for Deno
    npm install -g pm2
    
    # Create PM2 ecosystem file
    cat > ecosystem.config.js << 'EOF'
    module.exports = {
      apps: [{
        name: 'deno-app',
        script: 'deno',
        args: 'run --allow-net --allow-read main.ts',
        cwd: '/opt/deno-app',
        instances: 'max',
        exec_mode: 'cluster',
        env: {
          PORT: 8000,
          DENO_DIR: '/var/cache/deno'
        }
      }]
    };
    EOF
    
    # Start with PM2
    pm2 start ecosystem.config.js
    pm2 save
    pm2 startup

    6. Troubleshooting

    Common Issues

    1. Permission denied errors:

    bash
    # Check required permissions
    deno info
    
    # Run with specific permissions
    deno run --allow-net --allow-read --allow-write script.ts
    
    # Check which permissions are needed
    deno run --unstable --allow-all --inspect script.ts

    2. Module resolution errors:

    bash
    # Clear Deno cache
    deno cache --reload script.ts
    
    # Check module cache
    deno info script.ts
    
    # Use import map for resolution
    deno run --import-map=import_map.json script.ts

    3. TypeScript compilation errors:

    bash
    # Check TypeScript configuration
    deno run --config tsconfig.json script.ts
    
    # Skip type checking (development)
    deno run --no-check script.ts
    
    # Use specific TypeScript version
    deno run --unstable script.ts

    4. Network timeout issues:

    bash
    # Increase download timeout
    export DENO_TIMEOUT=60000
    
    # Use specific registry
    deno run --import-map=import_map.json script.ts
    
    # Check network connectivity
    deno run --allow-net -e "console.log(await fetch('https://deno.land'))"

    Debug Information

    bash
    # Get Deno information
    deno info
    
    # Check specific script dependencies
    deno info main.ts
    
    # Enable debug logging
    RUST_LOG=debug deno run script.ts
    
    # Check cache location
    echo $DENO_DIR
    ls -la ~/.cache/deno/

    7. Security Considerations

    Permission Model

    bash
    # Minimal permissions (recommended)
    deno run --allow-net=api.example.com --allow-read=./data script.ts
    
    # File system permissions
    deno run --allow-read=/var/data --allow-write=/tmp script.ts
    
    # Network permissions
    deno run --allow-net=:8000,api.example.com script.ts
    
    # Environment variable access
    deno run --allow-env=PORT,HOST script.ts

    Secure Deployment

    bash
    # Create restricted user
    sudo useradd -r -s /bin/false -d /opt/deno-app deno-app
    
    # Set secure file permissions
    sudo chmod 750 /opt/deno-app
    sudo chown -R deno-app:deno-app /opt/deno-app
    
    # Use systemd security features
    cat > /etc/systemd/system/deno-app.service << 'EOF'
    [Unit]
    Description=Deno Application
    After=network.target
    
    [Service]
    Type=simple
    User=deno-app
    Group=deno-app
    WorkingDirectory=/opt/deno-app
    ExecStart=/usr/local/bin/deno run --allow-net=:8000 --allow-read=/opt/deno-app main.ts
    Restart=always
    RestartSec=3
    
    # Security settings
    NoNewPrivileges=true
    PrivateTmp=true
    ProtectSystem=strict
    ProtectHome=true
    ReadWritePaths=/opt/deno-app
    CapabilityBoundingSet=
    
    [Install]
    WantedBy=multi-user.target
    EOF

    Code Security

    typescript
    // Validate environment variables
    const port = parseInt(Deno.env.get("PORT") || "8000");
    if (isNaN(port) || port < 1 || port > 65535) {
      throw new Error("Invalid port number");
    }
    
    // Sanitize inputs
    import { escape } from "https://deno.land/x/html_escape@v1.1.5/mod.ts";
    
    function sanitizeInput(input: string): string {
      return escape(input);
    }
    
    // Use HTTPS for external requests
    const response = await fetch("https://api.example.com/data", {
      headers: {
        "User-Agent": "MyApp/1.0"
      }
    });

    8. Performance Tuning

    Runtime Optimization

    bash
    # Enable V8 optimizations
    deno run --v8-flags="--max-old-space-size=4096" script.ts
    
    # Use Worker threads for CPU-intensive tasks
    deno run --allow-worker script.ts
    
    # Enable JIT compilation
    deno run --unstable --allow-all script.ts

    Application Performance

    typescript
    // Use efficient JSON parsing
    import { parse } from "https://deno.land/std@0.208.0/jsonc/mod.ts";
    
    // Implement caching
    const cache = new Map<string, any>();
    
    function getCachedData(key: string) {
      if (cache.has(key)) {
        return cache.get(key);
      }
      
      const data = expensiveOperation(key);
      cache.set(key, data);
      return data;
    }
    
    // Use streaming for large files
    const file = await Deno.open("large-file.txt");
    const readable = file.readable;

    Memory Management

    bash
    # Monitor memory usage
    deno run --inspect=127.0.0.1:9229 script.ts
    
    # Set memory limits
    deno run --v8-flags="--max-old-space-size=1024" script.ts
    
    # Use WeakMap for memory-sensitive caches
    const cache = new WeakMap();

    9. Backup and Restore

    Project Backup

    bash
    #!/bin/bash
    # backup-deno-project.sh
    
    PROJECT_DIR="/opt/deno-app"
    BACKUP_DIR="/var/backups/deno"
    DATE=$(date +%Y%m%d_%H%M%S)
    
    mkdir -p $BACKUP_DIR
    
    # Backup project files
    tar -czf $BACKUP_DIR/deno_project_$DATE.tar.gz \
        -C $PROJECT_DIR \
        --exclude='.deno' \
        --exclude='node_modules' \
        .
    
    # Backup configuration
    cp /etc/systemd/system/deno-app.service $BACKUP_DIR/
    
    echo "Project backup completed: $BACKUP_DIR/deno_project_$DATE.tar.gz"

    Cache Management

    bash
    #!/bin/bash
    # backup-deno-cache.sh
    
    DENO_DIR=${DENO_DIR:-"$HOME/.cache/deno"}
    BACKUP_DIR="/var/backups/deno"
    DATE=$(date +%Y%m%d_%H%M%S)
    
    # Backup Deno cache
    tar -czf $BACKUP_DIR/deno_cache_$DATE.tar.gz -C $DENO_DIR .
    
    # Clean old cache
    deno cache --reload --lock=lock.json deps.ts

    Dependency Lock

    bash
    # Generate lock file
    deno cache --lock=lock.json --lock-write deps.ts
    
    # Verify integrity
    deno cache --lock=lock.json deps.ts
    
    # Update dependencies
    deno cache --reload --lock=lock.json --lock-write deps.ts

    10. System Requirements

    Minimum Requirements

  • CPU: 1 core, 1.0 GHz
  • RAM: 512MB
  • Storage: 100MB
  • Network: Broadband for module downloads
  • CPU: 2+ cores, 2.0+ GHz
  • RAM: 2GB+
  • Storage: 1GB+ SSD
  • Network: High-speed for development
  • Enterprise Requirements

  • CPU: 4+ cores, 3.0+ GHz
  • RAM: 8GB+
  • Storage: 10GB+ NVMe
  • Network: Gigabit Ethernet
  • 11. Support

    Official Resources

  • Website: https://deno.land
  • GitHub: https://github.com/denoland/deno
  • Documentation: https://deno.land/manual
  • Standard Library: https://deno.land/std
  • Community Support

  • Discord: https://discord.gg/deno
  • Reddit: r/Deno
  • Stack Overflow: [deno] tag
  • GitHub Discussions: https://github.com/denoland/deno/discussions
  • 12. Contributing

    How to Contribute

    1. Fork the repository on GitHub

    2. Create a feature branch

    3. Submit pull request

    4. Follow Rust and TypeScript coding standards

    5. Include tests and documentation

    Development Setup

    bash
    # Clone repository
    git clone https://github.com/denoland/deno.git
    cd deno
    
    # Install Rust
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
    # Build Deno
    cargo build
    
    # Run tests
    cargo test

    13. License

    Deno is licensed under the MIT License.

    Key points:

  • Free to use, modify, and distribute
  • Commercial use allowed
  • No warranty provided
  • Attribution required
  • 14. Acknowledgments

    Credits

  • Deno Team: Core development team led by Ryan Dahl
  • Rust Community: Language and ecosystem
  • V8 Project: JavaScript engine
  • TypeScript Team: Type system support
  • 15. Version History

    Recent Releases

  • v1.40.x: Latest stable with performance improvements
  • v1.39.x: Enhanced TypeScript support
  • v1.38.x: Improved standard library
  • Major Features by Version

  • v1.40: Performance optimizations, better error messages
  • v1.35: Deno 2.0 preparation features
  • v1.30: Enhanced Web APIs support
  • 16. Appendices

    A. Hello World Example

    typescript
    // main.ts
    import { serve } from "https://deno.land/std@0.208.0/http/server.ts";
    
    const handler = (request: Request): Response => {
      const body = `Hello, Deno! You requested ${request.url}`;
      return new Response(body, { status: 200 });
    };
    
    console.log("Server running on http://localhost:8000");
    await serve(handler, { port: 8000 });
    bash
    # Run the server
    deno run --allow-net main.ts

    B. REST API Example

    typescript
    // api.ts
    import { Application, Router } from "https://deno.land/x/oak@v12.6.1/mod.ts";
    
    const router = new Router();
    
    router
      .get("/", (context) => {
        context.response.body = "Hello World!";
      })
      .get("/api/users", (context) => {
        context.response.body = { users: ["Alice", "Bob"] };
      })
      .post("/api/users", async (context) => {
        const body = await context.request.body().value;
        context.response.body = { created: body };
      });
    
    const app = new Application();
    app.use(router.routes());
    app.use(router.allowedMethods());
    
    console.log("API server running on http://localhost:3000");
    await app.listen({ port: 3000 });

    C. Database Integration

    typescript
    // database.ts
    import { Client } from "https://deno.land/x/postgres@v0.17.0/mod.ts";
    
    const client = new Client({
      user: "user",
      database: "test",
      hostname: "localhost",
      password: "password",
      port: 5432,
    });
    
    await client.connect();
    
    // Query example
    const result = await client.queryObject("SELECT * FROM users");
    console.log(result.rows);
    
    await client.end();

    D. Testing Example

    typescript
    // test.ts
    import { assertEquals } from "https://deno.land/std@0.208.0/testing/asserts.ts";
    
    function add(a: number, b: number): number {
      return a + b;
    }
    
    Deno.test("addition test", () => {
      assertEquals(add(2, 3), 5);
    });
    
    Deno.test("async test", async () => {
      const response = await fetch("https://httpbin.org/json");
      assertEquals(response.status, 200);
    });
    bash
    # Run tests
    deno test --allow-net

    ---

    For more information and updates, visit https://github.com/howtomgr/deno