Try several Linux distros through the terminal
Distrobox is a software tool that allows you to run any Linux distribution in the terminal.
It aims to let you run a variety of software in addition to the host distro without any issues.
For example – is there something that is only available in the AUR and you want to access it from your Ubuntu system? Distrobox can offer you this comfort.
So what exactly is the Distrobox?
Distrobox is a wrapper for
docker (Do you prefer). Distrobox’s raison d’être is to integrate the containers into your system, as if it were native software.
It integrates with removable devices (USB storage devices), D-Bus, user’s $HOME directory, Wayland and X11 sockets, and more!
Long story short:
Distrobox is a way to make containerized software integrate like native apps, even if that containerized software is from a completely different distribution.
The best thing about it is that you can create a development environment without needing root privileges.
You don’t need to change your host distribution just because of software compatibility issues. You can continue to use what you are comfortable with and use Distrobox to fill the backward/forward software compatibility gap using any other Linux distribution.
Features of Distrobox
Now that you have an idea for Distrobox, what does it allow you to do overall? Are the features useful for your use case?
Let me mention the main strengths of Distrobox:
- Ability to create a test environment to make changes without affecting your host distro.
- A development environment that doesn’t need sudo privileges can be flexible for your work. For example, if you have a work laptop, a sudoless setup might help.
- An easy way to manage multiple environments.
- Supports a variety of distros.
How to install Distrobox?
There is a prerequisite for installing Distrobox. That is, you must have either
docker installed. If you have a relatively modern Linux distribution, I recommend installing
podman from your software repositories. Otherwise, install
docker and follow the steps mentioned below.
As of this writing, Distrobox is available in the following repositories:
- Arch Linux (AUR)
- EPEL 8 and later
- Fedora 34 and later
- Ubuntu 22.10 and later
As you may have noticed, the latest publicly available version of Ubuntu is Ubuntu 22.04. Not many distros have Distrobox packaged yet…
If you can’t find it in the repositories, you can run the following command to install Distrobox:
curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sudo sh
The above command will download a shell script and run it with superuser privileges. If you can’t verify the source yourself, here’s the command you can use without worrying about granting superuser privilege to an unknown script.
curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh -s -- --prefix ~/.local
Now that you have Distrobox installed, let’s move on to some usage examples.
First steps with Distrobox
Having a screwdriver in your toolbox but never using it is not going to improve your skill. So let’s go over some basic commands to use distribution boxwhat they do and more.
Also, if you’re curious, you can take a look at this video from a fellow YouTuber who tried Distrobox on Fedora Silverblue:
1. Create a new container
A “container” in this context does not refer to containerized software like nextcloud, syncthing, etc., but rather to an operating system itself.
The syntax for creating a new container is:
distrobox-create --name CONTAINER-NAME --image OS-NAME:VERSION
Here you can specify the name you want to address your container by (CONTAINER-NAME), the name of the operating system you want to use (OS-NAME) and its version (VERSION).
Let’s see how to create a new container for Fedora 36 with the name ‘fedoraonfoss‘. I will do it with the following command:
distrobox-create --name fedoraonfoss --image fedora:36
You can also replace “36” with “latest” in case you want the latest version of any operating system.
This command will only take a moment to download the container image for Fedora 36.
Once the process is complete, you will receive a message informing you that the container has been created.
2. Start and enter the container
An operating system container is useless if we don’t start it and access its shell.
To do this, use the ‘distrobox-enter‘ ordered. The syntax is as follows:
When you start the container for the first time, Distrobox will perform an automatic initial setup consisting of installing a few containers, configuring layouts, themes, icons, fonts, groups, users, etc.
Depending on your computer’s processing power, this may take a long time. Please wait about 15 minutes when powering on for the first time.
Once this is complete, you will automatically be dropped into the container shell.
If you look closely, earlier when I ran the ‘distrobox-enter’ command, the hostname displayed on my prompt was ‘itsfoss’. After the initial setup is complete, I am now in a shell with a different hostname, i.e. “fedoraonfoss”.
Let’s also check the VERSION of the ‘/etc/os-release’ file.
3. Install the software
If you have reached this step, it is equivalent to installing Fedora freshly on your computer and the operating system has just started.
Just like a virtual machine, the operating system on our host machine doesn’t matter. We need to use the package manager provided by the guest operating system. Therefore, I will be using the DNF Package Manager on Fedora 36.
My host OS Ubuntu 22.04 LTS is not working [yet] have Foliate in proprietary repositories. But Fedora 36 has Foliate in the proprietary repositories. This way I can easily install Foliate as native software without resorting to heavy virtualization.
So, let’s install Foliate, since it’s available in the Fedora repositories but not in the Ubuntu repositories.
I will run the following command (in container shell) to install Foliate:
sudo dnf install foliate.noarch
Once dnf has finished installing Foliate, I will also run the following command (inside the container shell):
distrobox-export --app foliate
When you run the ‘distribution box export‘ from the container, it will also make the specified software available to the host operating system. This means that even though Foliate is installed in the Fedora container, I will be able to see it in the Application menu in Ubuntu.
As you can see, Foliate is visible in Ubuntu’s Application menu, even though it was installed in a Fedora 36 container.
Isn’t it amazing?
4. Integration of Distrobox apps
For the purposes of this demonstration, I downloaded The Linux command line PDF book, written by William Shotts. He saved it in my Documents directory.
Let’s see if containerized software – which is packaged for an entirely different operating system – reacts to changes like switching from light mode to dark mode.
Can it see my ‘~/Documents’ directory?
As you can see, theme changes are detected correctly, even the top bar has the correct icons for the close button and the hamburger menu.
Besides that, I don’t need to copy my epub file anywhere else. My ‘~/Documents’ directory was also successfully recovered.
Just like a native app!
5. Manage Distrobox images
Distobox provides a few commands that can be used to manage Distrobox images.
The first command is ‘distribution box list‘. As the name suggests, it lists all installed containers.
Since I only have one container, only “fedoraonfoss” appeared, even though it came out a few moments ago.
The second command is ‘distribution box stop‘. This command is used to stop a running container.
Below is the syntax:
distrobox stop CONTAINER-NAME
Finally, to remove any Distrobox container, use the ‘distrobox rm’ command. The syntax is given below:
distrobox rm CONTAINER-NAME
To explore more technical details, visit his GitHub page.
Distrobox is a wonderful tool that allows you to install operating systems as a simple podman/docker container and use them as a full-fledged operating system.
Using Distrobox, you can install virtually any software, even if it’s not available in your distro’s repositories, or even if it’s not packaged for your Linux distro. How useful is it?
There can be different use cases for Distrobox. What do you think you will use it for? Share your thoughts in the comments section below.