ScriptNet Solutions Support

How to install Chromium, Puppeteer and Puppeteer Cluster on Ubuntu Servers

Here is a simple, step-by-step guide to installing Node.js, the necessary Chromium system dependencies, Puppeteer, and Puppeteer Cluster on an Ubuntu server via SSH.

 

Step 1: Update System Packages and Install Node.js

Puppeteer requires a modern version of Node.js. It is best practice to install a recent LTS (Long Term Support) release using NodeSource:

sudo apt update && sudo apt upgrade -y

# Install curl if not already present
sudo apt install -y curl

# Setup Node.js LTS repository (e.g., Node 20.x or newer)
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

# Install Node.js and npm
sudo apt install -y nodejs

Confirm that Node.js and npm installed correctly by checking their versions:

node -v
npm -v

Step 2: Install Chromium System Dependencies

Modern versions of Puppeteer automatically download a compatible build of Chrome/Chromium during installation. However, Headless Chrome requires several low-level shared libraries on Ubuntu to run successfully. Install them via apt:

sudo apt install -y \
  ca-certificates \
  fonts-liberation \
  libasound2t64 \
  libatk-bridge2.0-0t64 \
  libatk1.0-0t64 \
  libcairo2 \
  libcups2t64 \
  libdbus-1-3 \
  libdrm2 \
  libgbm1 \
  libglib2.0-0t64 \
  libgtk-3-0t64 \
  libnspr4 \
  libnss3 \
  libpango-1.0-0 \
  libx11-6 \
  libxcb1 \
  libxcomposite1 \
  libxdamage1 \
  libxext6 \
  libxfixes3 \
  libxkbcommon0 \
  libxrandr2 \
  xdg-utils \
  unzip

Ensure the package manager finishes without any missing library error messages.

 

Step 3: Create a Project Directory and Install Puppeteer Packages

Create a new folder for your scraping/automation project, initialize a Node project, and install both puppeteer and puppeteer-cluster:

mkdir puppeteer-cluster-app
cd puppeteer-cluster-app
npm init -y

# Install Puppeteer and Puppeteer Cluster
npm install puppeteer puppeteer-cluster

Open your package.json file (cat package.json) and verify that puppeteer and puppeteer-cluster appear under "dependencies".

 

Step 4: Test the Installation with a Verification Script

Create a test script to make sure puppeteer-cluster launches and processes tasks correctly using the bundled Chromium browser.

  1. Create a file named test.js

nano test.js

Paste the following code into the editor. (Note: If you are logged into your server as the root user, you must include --no-sandbox arguments inside puppeteerOptions.):

const { Cluster } = require('puppeteer-cluster');

(async () => {
  // Launch the cluster with 2 concurrent workers
  const cluster = await Cluster.launch({
    concurrency: Cluster.CONCURRENCY_PAGE,
    maxConcurrency: 2,
    puppeteerOptions: {
      headless: 'new',
      args: ['--no-sandbox', '--disable-setuid-sandbox']
    }
  });

  cluster.on('taskerror', (err, data) => {
    console.error(`Error processing ${data}: ${err.message}`);
  });

  // Define the worker task
  await cluster.task(async ({ page, data: url }) => {
    await page.goto(url);
    const title = await page.title();
    console.log(`Successfully scraped title from ${url}: "${title}"`);
  });

  // Queue a test URL
  cluster.queue('https://example.com');

  // Wait for all tasks to complete and close the cluster
  await cluster.idle();
  await cluster.close();
  console.log('Puppeteer Cluster test completed successfully!');
})();

Save and exit (in Nano, press Ctrl + O, then Enter to save, and Ctrl + X to exit).

Run your test script:

node test.js

If the terminal outputs Successfully scraped title from [https://example.com]: "Example Domain" followed by Puppeteer Cluster test completed successfully!, your server environment, shared libraries, and cluster configuration are fully functional.