Software & AppsOperating SystemLinux

How To Change to Dark Theme in Ubuntu 22.04 Using Command Line

Ubuntu 6

Ubuntu 22.04, like its predecessors, offers a range of customization options to tailor your user experience. One such option is the ability to switch between light and dark themes. While the GUI offers a straightforward way to make this switch, you may prefer or need to use the command line. This article will guide you through the process of changing to a dark theme in Ubuntu 22.04 using the command line.

Understanding the Command Line

The command line, also known as terminal or shell, is a powerful tool that allows you to interact with your system directly. It can be more efficient and flexible than using the GUI, especially when you need to repeat tasks or automate them.

Accessing the Terminal

To open the terminal in Ubuntu, press Ctrl + Alt + T on your keyboard. Alternatively, you can search for ‘Terminal’ in your applications menu.

Switching to Dark Theme

To switch to a dark theme, we will use the gsettings command, which is a simple command line interface to GSettings. It allows you to get, set or monitor an individual key for changes.

Set GNOME Shell to Prefer Dark

The first command we’ll run will set the GNOME Shell to prefer dark themes. The GNOME Shell is the graphical shell of the GNOME desktop environment. Run the following command:

gsettings set org.gnome.shell.ubuntu color-scheme prefer-dark

Here, gsettings set is used to change a key’s value. org.gnome.shell.ubuntu color-scheme is the schema and key we’re changing. prefer-dark is the value we’re setting, which tells the shell to prefer dark themes.

Set GTK Theme for Legacy Apps

Next, we’ll set the GTK theme to a dark variant. GTK is a toolkit used to create graphical user interfaces. Some older or ‘legacy’ apps still use GTK for their interfaces. Run the following command:

gsettings set org.gnome.desktop.interface gtk-theme Yaru-dark

In this command, org.gnome.desktop.interface gtk-theme is the schema and key, and Yaru-dark is the value, which is a specific dark theme.

Set Color Scheme for New Apps

Finally, we’ll set the color scheme for new apps to prefer dark themes. Run the following command:

gsettings set org.gnome.desktop.interface color-scheme prefer-dark

This command is similar to the first one, but it applies to new apps instead of the shell.

Resetting the Color Scheme

If you want to switch back to the light theme, you can reset the color scheme with the following command:

gsettings reset org.gnome.shell.ubuntu color-scheme

In this command, gsettings reset is used to reset a key’s value to its default. org.gnome.shell.ubuntu color-scheme is the schema and key we’re resetting.

Automating the Process

If you frequently switch between themes, you can automate the process by creating a script. To create a script, you’ll need to create a new file, make it executable, and add the commands we used earlier. Here’s how you can do it:

  1. Open a terminal.
  2. Create a new file and make it executable:
touch switchDarkTheme.sh
chmod +x switchDarkTheme.sh
  1. Open the file in a text editor:
nano switchDarkTheme.sh
  1. Paste the following code into the file:
#!/bin/bash
gsettings set org.gnome.shell.ubuntu color-scheme prefer-dark
gsettings set org.gnome.desktop.interface gtk-theme Yaru-dark
gsettings set org.gnome.desktop.interface color-scheme prefer-dark
  1. Save and close the file (Ctrl+X, Y, Enter).
  2. Run the script:
./switchDarkTheme.sh

This script will switch your theme to dark. You can create a similar script for the light theme.

Conclusion

Switching to a dark theme in Ubuntu 22.04 using the command line is a straightforward process. Whether you prefer the aesthetics of a dark theme or it’s easier on your eyes, using the command line to make the switch is a quick and efficient method. Remember, the command line is a powerful tool, and with it comes the ability to customize your Ubuntu experience to your liking.

How do I open the terminal in Ubuntu 22.04?

To open the terminal in Ubuntu 22.04, press Ctrl + Alt + T on your keyboard. Alternatively, you can search for ‘Terminal’ in your applications menu.

What is the command to switch to a dark theme in Ubuntu 22.04?

The command to switch to a dark theme in Ubuntu 22.04 is:

gsettings set org.gnome.shell.ubuntu color-scheme prefer-dark
How do I reset the color scheme to switch back to the light theme?

To reset the color scheme and switch back to the light theme, you can use the following command:

gsettings reset org.gnome.shell.ubuntu color-scheme
Can I automate the process of switching between themes?

Yes, you can automate the process of switching between themes by creating a script. You can create a new file, make it executable, and add the necessary commands to switch the theme. Then, you can run the script whenever you want to switch themes.

How can I switch to a light theme using the command line?

To switch to a light theme using the command line, you can run the following commands:

gsettings reset org.gnome.shell.ubuntu color-scheme
gsettings reset org.gnome.desktop.interface gtk-theme
gsettings reset org.gnome.desktop.interface color-scheme

These commands will reset the color scheme to its default values, effectively switching to the light theme.

Leave a Comment

Your email address will not be published. Required fields are marked *