How to Install xclip on Ubuntu 26.04

If you need to interact with the clipboard from the terminal, xclip install ubuntu 26.04 is a common first step. xclip is a lightweight command-line tool that reads from standard input and places content into the X11 clipboard, making it easy to pipe command output directly into clipboard buffers for use in GUI applications. This guide covers everything you need to install, verify, and use xclip on Ubuntu 26.04 Resolute Raccoon, including an important note about Wayland compatibility.

In this tutorial you will learn:

  • How xclip differs from other clipboard tools and when to use it
  • How to install xclip on Ubuntu 26.04 using apt
  • How to verify the installation is working correctly
  • How to copy and paste content using xclip from the command line
  • When to use wl-clipboard as a Wayland-native alternative
Abstract illustration representing xclip clipboard tool installation on Ubuntu Linux terminal environment
xclip enables seamless clipboard interaction from the Linux command line

Software Requirements

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 26.04 Resolute Raccoon
Software xclip 0.13 (available in Ubuntu 26.04 main repository)
Other Privileged access to your Linux system as root or via the sudo command. An active X11 display session or XWayland support for clipboard operations.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

TL;DR

TL;DR
Install xclip with sudo apt install xclip, then use echo "text" | xclip -selection clipboard to copy content to the clipboard. Note that xclip requires an X11 or XWayland session.

Quick Steps to Install and Use xclip
Step Command/Action
1. Update package index sudo apt update
2. Install xclip sudo apt install xclip
3. Verify installation xclip -version
4. Copy text to clipboard echo "Hello" | xclip -selection clipboard

X11 vs Wayland Consideration

Before proceeding with xclip installation on Ubuntu 26.04, it is important to understand a key compatibility consideration. Ubuntu 26.04 ships with GNOME running exclusively on Wayland by default, having dropped the X11 GNOME session that was available in earlier releases. xclip is an X11 application, which means it communicates with the X clipboard protocol directly.

The good news is that Ubuntu 26.04 includes XWayland, a compatibility layer that allows X11 applications to run under Wayland. Consequently, xclip works in most desktop scenarios because XWayland bridges the gap. However, if you are operating in a minimal server environment without a display server, or if XWayland is not available, xclip will not function.

IMPORTANT
If you encounter errors like Error: Can't open display when running xclip, your session may lack a DISPLAY variable. For purely Wayland environments without XWayland, consider using wl-clipboard (the wl-copy and wl-paste commands) as a native Wayland alternative.

For most Ubuntu 26.04 desktop users, xclip will work transparently through XWayland. Moreover, many scripts and tools reference xclip by name, making it a practical choice even on Wayland-based systems where XWayland is present.

Install xclip on Ubuntu 26.04

The xclip install ubuntu 26.04 process is straightforward because the package is available in Ubuntu’s official main repository. Therefore, no additional PPAs or external sources are required.

  1. Update the package index: Before installing any new software, refresh your local package list to ensure you receive the latest available version:
    $ sudo apt update

    This command contacts the Ubuntu repositories and updates the local metadata cache.

  2. Install xclip: Install the package using apt:
    $ sudo apt install xclip

    apt will resolve any dependencies automatically and install xclip along with any required packages. You will be prompted to confirm with Y if apt does not install automatically.

Verify the Installation

After installation completes, verify that xclip is available and functioning correctly on your Ubuntu 26.04 system.

  1. Check the installed version: Confirm xclip is in your PATH and check the version:
    $ xclip -version

    You should see output similar to:

    xclip version 0.13
  2. Confirm the binary location: Optionally verify where the binary was installed:
    $ which xclip

    Expected output:

    /usr/bin/xclip
  3. Run a functional test: Test that xclip can actually interact with your clipboard by copying a string and then immediately reading it back:
    $ echo "xclip test" | xclip -selection clipboard && xclip -selection clipboard -o

    If the installation is working correctly, the output will be:

    xclip test

COMPLETED
If the functional test returns the text you piped in, xclip is installed and working correctly on your Ubuntu 26.04 system.

Terminal output of xclip functional clipboard test on Ubuntu 26.04 showing "xclip test" copied and pasted back via command line
Running a functional xclip test: piping text into the clipboard and reading it back confirms the installation is working

Basic xclip Usage Examples

Now that xclip is installed, here are the most common usage patterns you will encounter in everyday terminal work on Ubuntu 26.04.

  1. Copy command output to clipboard: Pipe any command’s output directly to the clipboard. This is particularly useful for copying file contents, IP addresses, or command results:
    $ cat /etc/hostname | xclip -selection clipboard

    After running this, you can paste the hostname into any GUI application using Ctrl+V.

  2. Copy a file’s contents to clipboard: Read a file and copy its entire contents:
    $ xclip -selection clipboard < ~/.ssh/id_ed25519.pub

    This is a common workflow for copying SSH public keys.

  3. Paste clipboard contents to the terminal: Output whatever is currently in the clipboard to stdout:
    $ xclip -selection clipboard -o

    You can additionally pipe this output into other commands for further processing.

  4. Use the primary selection buffer: X11 has multiple clipboard buffers. The “primary” selection contains whatever text you have highlighted with your mouse. Access it by omitting the -selection clipboard flag or by specifying primary:
    $ xclip -selection primary -o

IMPORTANT
xclip operates on three X11 clipboard selections: primary (mouse highlight), secondary (rarely used), and clipboard (standard Ctrl+C/Ctrl+V). Most users and scripts should target -selection clipboard to match the behavior of GUI copy-paste operations.

Terminal on Ubuntu 26.04 showing xclip copying /etc/hostname content to clipboard and reading it back with xclip -o
Using xclip to copy the system hostname from /etc/hostname into the clipboard and verify it with xclip -selection clipboard -o

Additionally, xclip integrates well into shell scripts and automation pipelines. For example, you can combine it with grep to extract and copy specific lines from log files, or with tools like curl to capture API responses directly to your clipboard without saving intermediate files.

For comprehensive documentation on all available flags and selection types, refer to the official xclip project page or consult the man page with man xclip.

Conclusion

This guide covered the complete xclip install ubuntu 26.04 process, from updating the package index through installation, verification, and practical usage examples. xclip is a reliable and widely-supported clipboard utility that integrates seamlessly into shell scripts and terminal workflows. On Ubuntu 26.04, it operates through XWayland, making it compatible with the default Wayland desktop environment. If you need native Wayland clipboard support without XWayland, wl-clipboard is the recommended alternative.

Frequently Asked Questions

  1. Does xclip work on Ubuntu 26.04 with Wayland? Yes, in most cases. Ubuntu 26.04 includes XWayland, which allows X11 applications like xclip to function under the Wayland compositor. However, if you see a Can't open display error, your environment may not have XWayland available, in which case wl-clipboard (providing wl-copy and wl-paste) is the recommended native Wayland alternative.
  2. What is the difference between xclip and xdotool or xsel? xclip focuses specifically on reading and writing X11 clipboard selections via stdin/stdout, making it ideal for piping in shell scripts. xsel offers similar clipboard functionality with slightly different flag conventions. xdotool is a broader tool for X11 automation that includes clipboard interaction but also handles keyboard/mouse simulation. For simple copy-paste automation on Ubuntu 26.04, xclip or xsel are typically the most appropriate choices.
  3. Why does xclip appear to hang when I run it without piping input? When you run xclip without providing input via a pipe or file redirection, it waits for input from stdin, just like commands such as cat. This is expected behavior. Either pipe content to it (e.g., echo "text" | xclip -selection clipboard) or redirect a file (e.g., xclip -selection clipboard < file.txt).
  4. How do I uninstall xclip from Ubuntu 26.04? Remove xclip with sudo apt remove xclip. To additionally remove any configuration files, use sudo apt purge xclip. Run sudo apt autoremove afterwards to clean up any orphaned dependencies.