How To Install A Desktop Environment On Gentoo Linux: XFCE Guide

How To Install A Desktop Environment On Gentoo Linux: XFCE Guide

How to Install a Desktop Environment on Gentoo Linux: XFCE Guide

The true power of Gentoo isn't just in its complexity, but in the total control it gives you over every single byte of your system. After spending hours compiling the perfect kernel, the next step is building a graphical environment that is just as lean, fast, and optimized as the base itself.

Hi all, and welcome to MusaBase! In today's guide, I will show you how to install a desktop environment on your Gentoo Linux system. This is a follow-up to my previous article on the Gentoo Linux Installation: Mastering the Most Complex OS, where we covered the base configuration.

In this article, we will continue the journey by installing XFCE, a lightweight and highly reliable desktop environment. We will dive into the essential Gentoo-specific configurations, including:

  • Preparing your Gentoo system for a graphical environment
  • Installing Xorg, the core display server for your desktop
  • Configuring make.conf to enable specific GPU and video card support
  • Installing XFCE along with its necessary dependencies
  • Configuring the system to correctly initialize the graphical session
  • And finally, booting into your new XFCE desktop on Gentoo

By the end of this tutorial, you will have a fully functional XFCE environment running smoothly on your Gentoo system. So without further ado, let's get started!







Prerequisites

Before we proceed, ensure that your system meets the hardware requirements for compiling packages: a minimum of 6GB RAM and at least 30GB of available storage space are highly recommended.

Please note that this guide focuses solely on the desktop setup and does not cover the initial OS installation. If you are starting from scratch, you should first complete the foundational setup by following my guide on configuring a base Gentoo Linux system. Once your base system is ready, you can return here to continue.

This tutorial is aligned with the Gentoo Official XFCE Wiki. If you encounter any issues or need deeper technical details on a specific flag, I recommend double-checking the commands here with the official documentation for complete accuracy.




Step 1: Prepare Gentoo System for Desktop Environment

I have an i5 4th gen processor with 4 cores and 10GB of RAM. This setup will complete in almost 9 hours on my PC, so I would highly recommend doing the installation steps overnight. If you have a more capable processor than mine, then this setup could take less time, but still, it's going to take time.

1.1: Choose a Desktop Profile

Note: If you installed Gentoo by following my previous Gentoo installation guide, then you can skip this step. If you have installed minimal Gentoo with no desktop profile then follow this step.

  • Run:
sudo eselect profile list | less
  • It'll print out all the available profiles.
  • If your init system is OpenRC, then note the index number of that profile. (e.g., [3] default/linux/amd64/23.0/desktop (stable) ).
  • If you are using systemd, then note the index number of desktop/systemd profile. (e.g., [4] default/linux/amd64/23.0/desktop/systemd (stable) ).
List of available Gentoo profiles displayed in terminal using eselect
  • To set or change profile, run:
sudo eselect profile set 3
Setting a Gentoo profile using the eselect command in terminal

1.2: Synchronize Local Portage Repository Tree

Portage depends on up-to-date information from repositories to know which packages and ebuilds are available. Synchronizing Portage tree ensures that the Gentoo system has the latest package information and supports multiple repos efficiently.

  • We can do this by running:
sudo emaint --auto sync

1.3: Add GPU to make.conf

We also need to add the GPU to /etc/portage/make.conf. The GPU variable will tell Portage which graphics drivers to enable when building packages. This will save time because without adding our specific GPU, Portage may build all possible drivers by default which will install drivers for all supported GPUs.

  • To add GPU variable, do the following:
sudo nano /etc/portage/make.conf
  • In the make.conf add the following line:
VIDEO_CARDS="virtio"

1.4: Updating Gentoo @worldset

Updating full Gentoo system (@worldset) before installing any other package is optional. But, by updating the system, we can safely install Xfce and run the desktop session because all packages would be synchronized, updated and if any missing dependencies are left, it will manage them automatically.

  • To update @worldset, run:
sudo emerge --ask --verbose --update --deep --newuse @world

1.5: Cleaning Gentoo System

After updating the Gentoo system, it is always a good idea to clean the system from unused packages plus dependencies. Unused dependencies may lead to unresolved conflicts for future updates. Cleaning them helps keep the system's dependency graph manageable.

  • To clean the unused packages & dependencies clutter, run:
sudo emerge --depclean



Step 2: Install Xorg and XFCE Desktop Environment

In this step, we'll add USE flags for our Display server (Xorg) and XFCE and then install them.

2.1: Install Display Server (Xorg/X11)

Xorg is an open-source display server. It is the core component for any desktop session to run successfully for Unix-like operating systems, like Linux distros or BSD operating systems. It allows the interaction between graphical applications and our display.

  • To add Xorg USE flags, run:
sudo emerge --verbose x11-base/xorg-drivers
  • After calculating all the dependencies in the xorg packages for Gentoo, Portage may ask you:
    • Would you like to add these changes to your config files? [Yes/No]
    • If you face this prompt, then type Yes and press ENTER to continue and follow next steps until you get the sudo etc-update step.
  • If Portage prompts:
    • Would you like to merge these packages? [Yes/No]
    • Type Yes and press ENTER to install Xorg.

2.2: Add USE Flags for XFCE

  • To add XFCE base and extra package's USE flags, run:
sudo emerge --ask xfce-base/xfce4-meta xfce-extra/xfce4-notifyd
  • After calculating the dependencies, Portage will ask you:
    • Would you like to add these changes to your config files? [Yes/No]. As shown below in the second image.
    • Type Yes and press ENTER and it will add XFCE's USE flags to a temporary file.

2.3: Update Config Files

In previous steps we emerged the xorg and xfce packages. But before actually installing those packages we need to add USE flags to the package.use file. By performing Step 2.1 & 2.2, we have successfully added USE flags for xorg and xfce. Now we need to update our config files to actually install these packages.

  • To update config files, run:
sudo etc-update
  • After a few seconds, it will prompt you with options to edit a single or all files with their corresponding number.
  • Type -3 and press ENTER and it will update all config files.

2.4: Install XFCE Desktop

Now that our USE flags have been added and the system is up-to-date, we can install XFCE without any interruption.

  • Re-run the emerge command again like this:
sudo emerge --ask xfce-base/xfce4-meta xfce-extra/xfce4-notifyd
  • This time, Portage will ask:
    • Would you like to merge these packages? [Yes/No]
    • Type Yes and press ENTER and the installation will begin.



Important Notes: Troubleshooting & USE Flags Details

Troubleshooting Xorg Installation Issues

If Xorg installation fails during sudo emerge --verbose x11-base/xorg-drivers, here are common solutions:

  • Check for missing dependencies:
    • Run: sudo emerge --ask --verbose --update --deep --newuse @world first to ensure all dependencies are updated.
    • Sometimes existing package conflicts cause Xorg installation to fail.
  • Verify MAKEOPTS in make.conf:
    • Check /etc/portage/make.conf for proper MAKEOPTS="-jX" setting (where X = CPU cores + 1).
    • For 4-core CPU: MAKEOPTS="-j5" is optimal.
  • Insufficient disk space:
    • Xorg installation requires significant space. Check with: df -h /usr/portage
    • Clear Portage distfiles: sudo eclean-dist --deep
  • Compiler issues:
    • If compilation fails, check current GCC profile: gcc-config -l
    • Switch to stable GCC version if needed.
  • Driver conflicts:
    • If you have both NVIDIA and Intel GPU, ensure only one VIDEO_CARDS entry exists in make.conf.
    • Remove conflicting entries and re-run Xorg installation.

Detailed USE Flags Explanation for Xorg & XFCE

When we run sudo emerge --verbose x11-base/xorg-drivers and sudo emerge --ask xfce-base/xfce4-meta, Portage automatically calculates and suggests USE flags. Here's what actually gets added:

Xorg USE Flags (Typically Added):

  • Xorg drivers USE flags:
    • INPUT_DEVICES="evdev synaptics": For touchpad and input device support
    • VIDEO_CARDS="virtio" (or your specific GPU): Graphics driver selection
    • xorg: Enables Xorg server support in various packages
    • udev or elogind: Device management based on your init system
  • Why these flags matter:
    • Without evdev, your keyboard/mouse may not work in X session
    • Missing synaptics disables touchpad gestures
    • Wrong VIDEO_CARDS causes blank screen or no graphics acceleration

XFCE USE Flags (Automatically Added):

  • XFCE core flags:
    • thunar: Enables Thunar file manager
    • xfce: Meta flag for all XFCE components
    • gtk3: GTK3 support (modern XFCE uses GTK3)
    • dbus: Inter-process communication for notifications
    • policykit: Privilege elevation for admin tasks
  • Optional but recommended flags Portage may add:
    • networkmanager: GUI network management
    • pulseaudio or pipewire: Sound system
    • screensaver: Screen locking
    • udisks: Automatic disk mounting



Step 3: Start XFCE Desktop Session

To launch XFCE session, we need to add an XFCE execution command in our ~/.xinitrc and then we can start the XFCE session.

3.1: Add XFCE Launch Command in ~/.xinitrc

  • Run:
sudo nano ~/.xinitrc
  • In the .xinitrc add:
exec startxfce4
  • After adding the launch command, press CTRL + O to save the changes, then press ENTER to apply the changes, then press CTRL + X to exit the file.

3.2: Launch XFCE Desktop Session

  • Now that everything is set, we are ready to launch the XFCE desktop session.
  • Simply run:
startx
#OR
startxfce4
# OR
sudo startxfce4
Launching XFCE desktop session on Gentoo with startxfce4 command in terminal
  • After a few seconds you will be in the XFCE desktop screen:
XFCE desktop environment home screen running on Gentoo Linux system

If Above Method Failed to Start XFCE Session

  • If XFCE session is not launching after running sudo startxfce4 then we need to change the launch command in ~/.xinitrc.
  • Run:
sudo nano ~/.xinitrc
  • Then replace the previous exec startxfce4 command with:
exec dbus-launch --exit-with-session xfce4-session
Modifying ~/.xinitrc with dbus-launch command for XFCE session management in Gentoo
  • After replacing the launch command, press CTRL + O to save the changes, then press ENTER to apply the changes, then press CTRL + X to exit the file.
  • Next, re-run:
sudo startxfce4
# OR
startxfce4
# OR
startx
  • And you should be booted into the XFCE desktop session.


πŸš€ Your Gentoo Workstation is Ready!

Congratulations! You now have a fully functional XFCE desktop session running on your Gentoo system. Successfully configuring a graphical environment on Gentoo is a significant achievement that requires both patience and technical precision. This setup provides you with a lightning-fast workstation tailored to your hardware.

Expand Your Unix-like Knowledge

πŸ”️ Arch Linux: If you enjoy the DIY nature of Gentoo but want to explore a different package management philosophy, check out my guide on The Complete Arch Linux Installation.

😈 FreeBSD: For those interested in moving beyond Linux into the world of professional Unix-like systems, follow my walkthrough on How to Install FreeBSD: The Power to Serve.

πŸ› ️ Support & Feedback: If you hit any snag or face issues while following this guide, please let me know in the comments below. I will be more than happy to help you troubleshoot.

I will be uploading more Gentoo content soon, including KDE, GNOME, and Wayland guides. Stay tuned!
101 out, I’ll see you in the next one! πŸš€

Load comments