Home Command line utilities How To Configure Mouse Support For Linux Virtual Consoles
Configure Mouse Support For Linux Virtual Console Using GPM

How To Configure Mouse Support For Linux Virtual Consoles

By sk
1268 Views

I use Oracle VirtualBox to test various Unix-like operating systems. Most of my VMs are headless servers that does not have graphical desktop environment. For a long time, I have been wondering how can we use the mouse in the text-based terminals in headless Linux servers. Thanks to GPM, today I learned that we can use Mouse in virtual consoles for copy and paste operations. GPM, acronym for General Purpose Mouse, is a daemon that helps you to configure mouse support for Linux virtual consoles. Please do not confuse GPM with GDM (GNOME Display manager). Both serves entirely different purpose.

GPM is especially useful in the following scenarios:

  • New Linux server installations or for systems that cannot or do not use an X windows system by default, like Arch Linux and Gentoo.
  • Use copy/paste operations around in the virtual terminals/consoles.
  • Use copy/paste in text-based editors and browsers (Eg. emacs, lynx).
  • Use copy/paste in text file managers (Eg. Ranger, Midnight commander).

In this brief tutorial, we are going to see how to use Mouse in Text-based terminals in Unix-like operating systems.

Install GPM In Linux

To enable mouse support in Text-only Linux systems, install GPM package. It is available in the default repositories of most Linux distributions.

On Arch Linux and its variants like Manjaro Linux, run the following command to install GPM:

$ sudo pacman -S gpm

On Debian, Ubuntu, Linux Mint:

$ sudo apt install gpm

On Fedora:

$ sudo dnf install gpm

On openSUSE:

$ sudo zypper install gpm

Once installed, enable and start GPM service using the following commands:

$ sudo systemctl enable gpm
$ sudo systemctl start gpm

In Debian-based systems, gpm service will be automatically started after you installed it, so you need not to manually start the service as shown above.

Configure Mouse Support For Linux Virtual Consoles

There is no special configuration required. GPM will start working as soon as you installed it and started gpm service.

Have a look at the following screenshot of my Ubuntu 18.04 LTS server before installing GPM:

Ubuntu 18.04 CLI

Ubuntu 18.04 CLI before installing GPM

As you see in the above screenshot, there is no visible Mouse pointer in my Ubuntu 18.04 LTS headless server. Only a blinking cursor and it won't let me to select a text, copy/paste text using mouse. In CLI-only Linux servers, the mouse is not useful at all.

Now check the following screenshot of Ubuntu 18.04 LTS server after installing GPM:

Configure Mouse Support For Linux Virtual Consoles Using GPM

Configure Mouse Support For Linux Virtual Consoles Using GPM

See? I can now be able to select the text.

To select, copy and paste text, do the following:

  • To select text, press the left mouse button and drag the mouse.
  • Once you selected the text, release the left mouse button and paste text in the same or another console by pressing the middle mouse button.
  • The right button is used to extend the selection, like in `xterm'.
  • If you're using two-button mouse, use the right button to paste text.

It's that simple!

Like I already said, GPM works just fine and there is no extra configuration needed. Here is the sample contents of GPM configuration file /etc/gpm.conf (or /etc/conf.d/gpm in some distributions):

# protected from evaluation (i.e. by quoting them).
#
# This file is used by /etc/init.d/gpm and can be modified by
# "dpkg-reconfigure gpm" or by hand at your option.
#
device=/dev/input/mice
responsiveness=
repeat_type=none
type=exps2
append=''
sample_rate=

In my example, I use USB mouse. If you're using different mouse, you might have to change the values of  device=/dev/input/mice and type=exps2 parameters.

For more details, refer man pages.

$ man gpm

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

2 comments

Michael Perlbach February 18, 2020 - 4:38 pm

Is not working with Midnight Commander with Ubuntu Bionic on a Windows 10 host – at least when I use MS Powershell.

Reply
sk February 18, 2020 - 4:40 pm

That’s unfortunate. It worked for me on Ubuntu 18.04 server.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More