Installing Pandoc - lightblueseas/linuxstuff GitHub Wiki

Installing Pandoc and Using the Automated Script

Introduction

Pandoc is a universal document converter that allows you to convert between various markup formats such as Markdown, LaTeX, HTML, and more. This guide provides two ways to install Pandoc:

  1. Manual Installation: Installing Pandoc using package managers.
  2. Automated Installation: Using a Bash script to check for Pandoc and install it if necessary.

1. Manual Installation

Debian/Ubuntu-based Systems:

Run the following command to install Pandoc:

sudo apt update && sudo apt install -y pandoc

Arch Linux / Manjaro:

For Arch-based distributions, use pacman:

sudo pacman -Syu --noconfirm pandoc

macOS:

For macOS users, install Pandoc using Homebrew:

brew install pandoc

If Homebrew is not installed, you can install it by following the instructions at Homebrew's official website.

Windows:

Download and install Pandoc from the official site: Pandoc Downloads


2. Automated Installation Script

Instead of manually installing Pandoc, you can use the following Bash script to check for Pandoc and install it automatically based on your OS.

Installation Script:

Save the following script as install-pandoc.sh:

#!/bin/bash

# Function to check if a command exists
command_exists() {
    command -v "$1" >/dev/null 2>&1
}

# Check if Pandoc is installed
if command_exists pandoc; then
    echo "Pandoc is already installed: $(pandoc --version | head -n 1)"
    exit 0
fi

echo "Pandoc is not installed. Attempting to install it..."

# Detect the package manager and install Pandoc
if [ -f /etc/debian_version ](/lightblueseas/linuxstuff/wiki/--f-/etc/debian_version-); then
    # Debian-based (Ubuntu, Debian)
    sudo apt update && sudo apt install -y pandoc
elif [ -f /etc/arch-release ](/lightblueseas/linuxstuff/wiki/--f-/etc/arch-release-); then
    # Arch Linux
    sudo pacman -Syu --noconfirm pandoc
elif [ "$(uname)" == "Darwin" ](/lightblueseas/linuxstuff/wiki/-"$(uname)"-==-"Darwin"-); then
    # macOS
    if command_exists brew; then
        brew install pandoc
    else
        echo "Homebrew is not installed. Please install Homebrew first: https://brew.sh/"
        exit 1
    fi
else
    echo "Unsupported operating system. Please install Pandoc manually: https://pandoc.org/installing.html"
    exit 1
fi

# Verify if the installation was successful
if command_exists pandoc; then
    echo "Pandoc successfully installed: $(pandoc --version | head -n 1)"
else
    echo "Pandoc installation failed. Please try installing it manually."
    exit 1
fi

Running the Script

To execute the script, follow these steps:

  1. Make the script executable:

    chmod +x install-pandoc.sh
    
  2. Run the script:

    ./install-pandoc.sh
    

The script will check if Pandoc is installed and install it using the appropriate package manager.


Conclusion

This guide provides both a manual and an automated way to install Pandoc on Linux and macOS. The automated script ensures that installation is handled efficiently, reducing the need for manual intervention.