Skip to content
Printers Setup
Menu

Computers

Add a Printer from the Linux Command Line with lpadmin

Written by Printers Setup Editorial Team · Updated

A woman seen from behind working at a computer on a home desk
Photo: Shixart1985, CC BY 2.0, via Wikimedia Commons

The desktop printer settings on Ubuntu, Fedora or Mint work well, but sometimes you need the terminal: a server with no screen, a Raspberry Pi, a script for several machines, or a printer the graphical tool will not find. You can add a printer from the Linux command line with a single CUPS command, lpadmin, plus a few helpers to check the result. This guide uses commands documented in the CUPS manual pages, so they work on any distribution that uses CUPS.

How Linux printing is organised

CUPS is the printing system on almost every Linux desktop. It keeps a list of destinations (print queues). Each destination has a name, a device URI that says where the printer is, and a model that says how to talk to it. The CUPS manual describes lpadmin as the tool that configures printer and class queues, while lpinfo lists the devices and drivers available.

Modern network printers speak IPP, the Internet Printing Protocol, and can describe themselves to CUPS. That is called driverless printing, and it is why most current printers need no driver on Linux at all.

Step 1: check CUPS and find the printer

First confirm the scheduler is running:

lpstat -r
lpstat -p -d

The first command reports whether the CUPS scheduler is running. The second lists existing printers and the current default, so you can see whether the printer has already been added automatically.

Next, find the printer’s address. The easiest way is to print its network configuration page from the control panel; our guide to finding a printer’s IP address lists other methods. Reserve the address in your router so it does not change. You can also ask CUPS what it can see:

sudo lpinfo -v

Network printers usually appear with ipp://, ipps:// or dnssd:// URIs. USB printers appear with usb://.

Step 2: add the printer with IPP Everywhere

The CUPS admin guide gives this example for a network printer at an IP address, and says the everywhere model is used for nearly all modern network printers sold since about 2009:

sudo lpadmin -p Office -E -v ipp://192.168.1.20/ipp/print -m everywhere

What each part does, according to the lpadmin manual:

  • -p Office names the queue. CUPS allows any printable characters except space, tab, / and #, and names are not case-sensitive.
  • -E after -p enables the destination and makes it accept jobs.
  • -v sets the device URI, here IPP to the printer’s address.
  • -m everywhere queries the printer and builds the queue from its answers.

You can add a description and location with -D "Upstairs laser" and -L "Study".

Step 3: set the default printer

Two options, depending on who should get the default:

sudo lpadmin -d Office      # server default for all users
lpoptions -d Office         # default for your own account

The lpadmin manual says -d sets the server default destination. lpoptions -d sets your personal default; run as root it applies to all users through /etc/cups/lpoptions.

Step 4: print a test

lp -d Office /etc/hosts
lpstat -o

lp -d sends a file to the named destination; any small text file will do. lpstat -o shows jobs that are still queued. If a job sits there, check the printer’s address and that it is switched on. Our test page guide shows how to print the printer’s own self-test page too.

Older printers without IPP Everywhere

For a printer that does not support driverless printing, CUPS’s admin guide shows an example using a raw socket connection and one of the CUPS sample drivers:

sudo lpadmin -p OldLaser -E -v socket://192.168.1.30 -m drv:///sample.drv/laserjet.ppd

lpinfo -m lists the models installed on your system; your distribution may offer packages with more drivers. Be aware that the lpadmin manual says models other than everywhere are deprecated and will not be supported in a future version of CUPS, so check whether a newer printer firmware adds IPP Everywhere before relying on an old driver.

Change, share or remove a printer

  • Share it on the network: sudo lpadmin -p Office -o printer-is-shared=true, plus sharing enabled in CUPS. Our Raspberry Pi print server guide covers the full setup.
  • Set a default option: the manual’s example is -o number-up-default=2; the same pattern works for options such as sides-default=two-sided-long-edge.
  • Remove it: sudo lpadmin -x Office. CUPS warns that pending jobs for that destination are removed.

Quick reference

TaskCommand
Is CUPS running?lpstat -r
List printers and defaultlpstat -p -d
Show each printer’s device URIlpstat -v
List devices CUPS can seesudo lpinfo -v
Add a driverless network printersudo lpadmin -p NAME -E -v ipp://ADDRESS/ipp/print -m everywhere
Set the system defaultsudo lpadmin -d NAME
Set your own defaultlpoptions -d NAME
Print a filelp -d NAME file
Show queued jobslpstat -o
Remove a printersudo lpadmin -x NAME

If the printer will not add

  • “Unable to connect” or a long pause: check the address with ping, and that the printer is on the same network as the computer.
  • Wrong resource path: /ipp/print is the common path for IPP Everywhere printers, but not universal. Use the URI that lpinfo -v reports for the printer.
  • Jobs stop with the printer disabled: the default error policy for printers is “stop-printer”. Fix the cause, then enable the queue again with sudo cupsenable NAME.

Firewalls and discovery

If lpinfo or the desktop settings cannot see a printer you can ping, a firewall is a common cause. The CUPS firewall documentation lists the ports involved: IPP on TCP 631 for print jobs and status, and multicast DNS on UDP 5353 for finding printers. Older protocols use other ports, such as 9100 for raw AppSocket printing and 515 for LPD. If your distribution runs a firewall, allow mDNS for discovery, or skip discovery entirely by adding the printer with its IP address as shown above. Our guide to printer network ports explains what each port does and which ones home printers really need.

Why IPP Everywhere just works

The everywhere model works because the printer describes its own capabilities over IPP, so CUPS builds the queue without a model-specific driver. The same idea is behind AirPrint on Apple devices and Mopria on Android and Windows. Our explainer on driverless printing shows how the standards relate and how to tell whether a printer supports them before you buy.

On macOS and Raspberry Pi

macOS also uses CUPS, so lpstat, lp and lpadmin are available in Terminal; most people will still prefer the steps in our Mac printer guide. On Raspberry Pi OS the commands are identical to Debian and Ubuntu. For the graphical route on Ubuntu, see add a printer in Ubuntu, and for the same job on Windows, see add a printer with PowerShell.

Frequently asked questions

Do I need sudo to run lpadmin?

Usually yes on Ubuntu and similar systems, or membership of the printer admin group. The CUPS manual notes that lpadmin may ask for a password depending on the printing system configuration.

What does -m everywhere do?

It tells CUPS to query the printer over IPP and build the queue from what the printer reports, instead of using a driver or PPD file. The CUPS documentation says the everywhere driver is used for nearly all modern network printers sold since about 2009.

My printer is old and does not support IPP Everywhere. What now?

Use a driver package from your distribution or the maker, or a generic CUPS sample driver for basic printing. The CUPS admin guide shows a socket:// example with a sample LaserJet driver. Note that CUPS says PPD files and printer drivers are deprecated and will not be supported in a future version.

How do I remove a printer from the command line?

Run lpadmin -x followed by the printer name. CUPS warns that any pending jobs for that destination are removed and the current job is aborted.

Sources

PS

Printers Setup Editorial Team

Editorial team

The Printers Setup team writes and reviews step-by-step printer setup guides and checks them against the current menus of Windows, macOS, ChromeOS, iOS and Android.

Related guides