Use CUPS printing server on Windows 10

Printing on Windows is sometimes troublesome. When it is not working, you won’t have any chance to fix it yourself, debug or configure it more in-depth. This guide will show you a workaround on how to use the Linux CUPS printing client and server on Windows 10 using WSL2. The CUPS printer will be then added as a native Windows printer.

WSL2 is a subsystem on Windows to run Linux systems in an integrated container, like Docker. We’re going to install the default Ubuntu version using Windows Powershell.

Installing WSL2 Ubuntu and CUPS

Open Powershell as administrator and insert following command

wsl --install -d ubuntu

After that, reboot Windows, run the Ubuntu app from the start menu and configure a username and password for your new Ubuntu instance. Run following commands to setup CUPS

sudo apt update
sudo apt install cups
sudo service cups start

We create a script which will run the cups service at startup

#!/bin/sh
service cups start
sudo chmod +x /etc/init-wsl

The following commands will configure our printer on CUPS. In this case we are adding a remote IPP printer which won’t require any additional drivers

sudo lpadmin -p dell_1250c -m everywhere -o printer-is-shared=true -E -v http://192.168.178.2:631/printers/Dell_1250c
sudo lpoptions -d dell_1250c
  • dell_1250c is the name we’re going to define for the printer
  • everywhere is the printer driver, in this case a generic one for IPP printers
  • The URL is the IPP printer URL
  • lpoptions defines our printer as the default one

Note that it is also possible to add a physical printer attached via USB to your WSL2 Linux. An interesting guide on this can be found here.

CUPS server will be accessible on http://localhost:631

Now we open the Windows task scheduler and create a new startup task for Windows to run the WSL2 Ubuntu every time the computer starts. A more detailed guide on this can be found here but in short it is

  • Left pane click on Task Scheduler Library
  • On the right side right click on free space and choose Create Task
  • General: Give the task the name WSL Startup
  • General: Choose Run whether user is logged on or not and Run with highest privileges
  • General: Choose Configure for: Windows 10
  • In Trigger tab click on New > Begin the task: At startup
  • In Action tab click on New > Action: Start a program
    • Program/script: wsl
    • Arguments: -d ubuntu -u root /etc/init-wsl
  • In Conditions tab disable all AC power related options

Adding printer in Windows

To add the new printer go to the system settings and navigate to Devices > Printers & scanners. Click on Add new and wait until the link “The printer that i want isn’t listed” appears. Click on this link.

In the new window click on Add a printer using an IP address or hostname. Add the URL of your local CUPS server with the name of your printer, in this example http://localhost:631/printers/dell_1250c.

Print a test page and your local CUPS server should send the print job to the next destination. In case there’s any issue you can see queued and finished print jobs in the CUPS interface at http://localhost:631.

💬 Are you interested in our work or have some questions? Join us in our public Signal chat pi crew 👋
🪙 If you like our work or want to supprot us, you can donate MobileCoins to our address.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *