How to Setup Dual Monitors With XRandR

Xrandr Dualmonitor

While dual-monitor setups are a thing we take for granted when using Linux, it isn’t always a simple plug-and-play affair. You could be using a desktop environment that doesn’t want to work with your hardware or have a window manager that stubbornly decides to slap one of your displays with a lower resolution than the one it supports. For problems like these, XRandR proves to be an extraordinarily valuable tool.

Find Out the Resolutions Supported by Your Displays

Start by querying XRandR to see what resolutions are supported by your displays:

xrandr -q
Xrandr Query

In the screenshot, we see that a screen called HDMI-A-1 is connected with a resolution of 1920×1080. “Screen 0” is the space used for the entirety of the “screen real estate” that you get in your current configuration. In this case, it’s twice the width of the HDMI-A-1 monitor (3840×1080) because there’s another monitor with the same resolution set up to the right of the one we’re looking at. By scrolling further down the output, we can see that the second monitor is called DP-1.

Xrandr Secondmonitormode

The asterisk (*) next to a resolution represents the chosen mode. In the X protocol, resolutions are always labeled as “modes.” The plus (+) sign next to a resolution is what XRandR believes is the optimal mode for that particular display.

You’ll notice when you type xrandr -q in your terminal, your displays will always be prefixed with the type of cable they used to connect to the computer (e.g., HDMI, DP, VGA, DVI). This makes sure that display names are not overly complicated.

Setting Up XRandR Properly

For the sake of simplicity, the rest of this guide will presume that you’re using two DisplayPort monitors (DP) that have optimal resolutions at 1080p (1920×1080).

Let’s extend your two displays just to hop right into how XRandR works:

xrandr --auto --output DP-0 --mode 1920x1080 --left-of DP-1
xrandr --auto --output DP-1 --mode 1920x1080

Here’s a rundown of what these commands meant:

  • The --auto flag is used to either enable a disabled device that’s already connected or disable a device that is no longer detected. This helps correct some issues where a display may not be showing anything.
  • The first command tells XRandR to put your display that’s connected to the primary DisplayPort interface on your graphics hardware to set a resolution of 1920×1080 and orient the monitor to the left of your other display. If this wasn’t what you wanted to do, change --left-of to --right-of and you’ll be fine. You could also use --left-of in the second command instead to achieve the same thing.
  • The second command simply sets the resolution of the second monitor to 1920×1080.

Want to extend displays vertically? Just switch --left-of or --right-of to --above or --below.

Want to mirror both displays? Use --same-as instead. For example, if you’d like DP-1 to mirror DP-0, this is what you’d type:

xrandr --auto --output DP-1 --same-as DP-0

This is particularly useful when you want to use a projector on a laptop or something to that effect.

If you want to set a particular refresh rate, use the --rate flag:

xrandr --auto --output DP-0 --mode 1920x1080 --rate 60

Remember, XRandR is not magic. It cannot set refresh rates that it doesn’t know your display supports. You can’t, for example, turn your 60 Hz display into a 144 Hz uber-spicy gaming monitor with one simple command unless that’s a refresh rate that it supports. The query we did at the very beginning will tell you in one neat column what refresh rates are available for a given resolution with your particular hardware.

Also, keep in mind that the desktop environment or window manager you currently use may not allow you to set refresh rates higher than your slowest monitor’s maximum rate.

To turn off a monitor, just use --off:

xrandr --output DP-1 --off

Note how I do not include --auto here. It’s not really necessary because it just serves as a contingency to turn on displays that may be disabled but connected. This is not what we want to do right now.

To turn a monitor back on, set its mode with the --auto flag:

xrandr --auto --output DP-1 --mode 1920x1080

Making XRandR Settings Persist Across Reboots

Now that you’ve set up your monitors exactly how you’d want them, don’t reboot just yet. Your computer will lose these settings as soon as it starts again. To prevent this, we’re going to have to write a script.

Create a file called in your home directory. For the sake of simplicity, we’ll go back to our first example where we set up two DisplayPort monitors with 1080p resolution, with DP-0 being the monitor on the left. In that case, this is what we populate the file with:

xrandr --auto --output DP-0 --mode 1920x1080 --left-of DP-1
xrandr --auto --output DP-1 --mode 1920x1080

If you have another command in mind, replace what I wrote with it and save the file. Just make sure that the top line (#!/bin/bash) is left alone. That helps ensure that Linux uses the right shell to execute your script.

Don’t forget to open your terminal again and make this script executable:

chmod a+x ~/

All you have to do now is set this script as a startup program in your desktop environment of choice.

Is There a GUI for This?

Every desktop environment has a front end to XRandR. You just have to look through your settings. If you know where to set your resolution in your desktop, you found the GUI.

But if you’re using a window manager or a really weird environment, you might not have a pre-installed XRandR front end. In these cases, you may want to try out ARandR, a simple interface that’s straightforward and even saves pre-made scripts for you.

To use it, open the application and navigate to the “Outputs” menu. From there, just set the resolution and orientation you’d like for each output.

Xrandr Arandr

Save your changes and enjoy!

Taking Your Display Experience Further

If you’re a bit more adventurous, you may want to give Wayland a go. The kinks haven’t been fully worked out, but a lot of the limitations that could lead you to need to use XRandR to configure your displays might not exist if you switch from X11 to Wayland. X stopped being developed a while ago, so now’s as good a time as any to run both concurrently and see where you find the most happiness!

Image credit: Minh Phuc via Pexels; all screenshots by author

Is this post useful?
Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Miguel Leiva-Gomez
Miguel Leiva-Gomez - Staff Writer

Miguel has been a business growth and technology expert for more than a decade and has written software for even longer. From his little castle in Romania, he presents cold and analytical perspectives to things that affect the tech world.